Roblox Studio 预期“}”(在第 5 行关闭“{”),得到 'game'
Roblox Studio Expected '}' (to close '{' at line 5), got 'game'
我制作了 AlvinBlox 宠物蛋的教程,但它不起作用。我不断收到一条错误消息:
固定:
18:34:03.253 - ServerScriptService.PetModule:7: Expected '}' (to close
'{' at line 5), got 'game' 18:34:03.255 - Requested module
experienced an error while loading
新问题:
19:26:49.473 - ServerScriptService.PetModule:54:解析 if 语句时预期 'then',得到 'number'
这是脚本:
local petModule = {}
petModule.pets = {
["Legendary"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Dominus Ultimus");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Demonic Dominus");
};
["Rare"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Forgotten kraken");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Mythical Demon");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Creature of light");
};
["Uncommon"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Angel");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Pumkin");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Ninja");
};
["Common"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Dog");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Cat");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Fox");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Panda");
};
}
-- Weighted Selection o((>ω< ))o
petModule.rarities = {
["Legendary"] = 7.5; -- Change the Legendary,Rare,Uncommon and Common
-- number to increase or decrease chance
["Rare"] = 15;
["Uncommon"] = 25;
["Common"] = 50;
}
petModule.chooseRandomPet = function()
local randomNumber = math.random(1,100)
local counter = 0
for rarity, weight in pairs(petModule.rarities) do
counter = counter + weight
if Random number <= counter then --This is the problem
local rarityTable = petModule.pets[rarity]
local chosenPet = rarityTable[math.random(1,#rarityTable)]
return chosenPet
end
end
end
return petModule
对于你的新问题,我看到你在 if 语句中输入了随机数而不是随机数。所以它应该看起来像这样“如果随机数 <= 那么计数器”。
我制作了 AlvinBlox 宠物蛋的教程,但它不起作用。我不断收到一条错误消息:
固定:
18:34:03.253 - ServerScriptService.PetModule:7: Expected '}' (to close '{' at line 5), got 'game' 18:34:03.255 - Requested module experienced an error while loading
新问题: 19:26:49.473 - ServerScriptService.PetModule:54:解析 if 语句时预期 'then',得到 'number'
这是脚本:
local petModule = {}
petModule.pets = {
["Legendary"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Dominus Ultimus");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Demonic Dominus");
};
["Rare"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Forgotten kraken");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Mythical Demon");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Creature of light");
};
["Uncommon"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Angel");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Pumkin");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Ninja");
};
["Common"] = {
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Dog");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Cat");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Fox");
game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Panda");
};
}
-- Weighted Selection o((>ω< ))o
petModule.rarities = {
["Legendary"] = 7.5; -- Change the Legendary,Rare,Uncommon and Common
-- number to increase or decrease chance
["Rare"] = 15;
["Uncommon"] = 25;
["Common"] = 50;
}
petModule.chooseRandomPet = function()
local randomNumber = math.random(1,100)
local counter = 0
for rarity, weight in pairs(petModule.rarities) do
counter = counter + weight
if Random number <= counter then --This is the problem
local rarityTable = petModule.pets[rarity]
local chosenPet = rarityTable[math.random(1,#rarityTable)]
return chosenPet
end
end
end
return petModule
对于你的新问题,我看到你在 if 语句中输入了随机数而不是随机数。所以它应该看起来像这样“如果随机数 <= 那么计数器”。