Search code examples
luaroblox

Roblox Studio Expected '}' (to close '{' at line 5), got 'game'


I did a tutorial of AlvinBlox's Pet Egg but it's not working. I keep on getting an error saying:

Fixed:

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

New Problem: 19:26:49.473 - ServerScriptService.PetModule:54: Expected 'then' when parsing if statement, got 'number'

This is the script:

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

Solution

  • For your new problem, I saw that you typed Random number instead of random number in the if statement. So it should look like this "if random number <= counter then".