Issue while in game but not in studio

I have this script that runs perfectly in studio but doesn’t work at all in game, it doesn’t even print any error in the console.

I don’t have any idea why it does that. Could somone help me ??

RS.Remotes.Event.SellAll.OnServerEvent:Connect(function(player)
    local Ores = {
        ["Rocks"] = 0,
        ["Diamonds"] = 0,
        ["Iron"] = 0,
        ["Gold"] = 0
    }
    
    for i, Ore in pairs(player:WaitForChild("PlayerData"):WaitForChild("Ores"):GetChildren()) do
        for k, v in pairs(Ores) do
            if k == tostring(Ore) then
                Ores[tostring(Ore)] = Ore.Value
            end
        end
    end
    local Rebirths = player:WaitForChild("leaderstats"):WaitForChild("Rebirths")
    
    local RocksCoinsGet = Ores["Rocks"] * 2 * Rebirths.Value
    local IronCoinsGet =  Ores["Iron"] * 7 * Rebirths.Value
    local GoldCoinsGet = Ores["Gold"] * 25 * Rebirths.Value
    local DiamondsCoinsGet = Ores["Diamonds"] * 100 * Rebirths.Value
    
    local Sum = RocksCoinsGet + DiamondsCoinsGet + IronCoinsGet + GoldCoinsGet
    local Coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
    Coins.Value = Coins.Value + Sum
    
    for i, v in pairs(player:WaitForChild("PlayerData"):WaitForChild("Ores"):GetChildren()) do
        v.Value = 0
    end
end)

RS.Remotes.Event.SellOre.OnServerEvent:Connect(function(player, OreToSell)
    local Rebirths = player:WaitForChild("leaderstats"):WaitForChild("Rebirths")
    local Coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
    local Ore = player:WaitForChild("PlayerData"):WaitForChild("Ores"):WaitForChild(OreToSell)
    
    local OreTosellValue = player:WaitForChild("PlayerData"):WaitForChild("Ores")[OreToSell].Value
    
    local Sum = OreTosellValue * RS.Modules.Ores[OreToSell].Value * Rebirths.Value
    
    Ore.Value = 0
    Coins.Value = Coins.Value + Sum
end)
1 Like

It would be helpful to provide any insight on what isn’t working and what it’s meant to do, and you also really do not need to spam WaitForChild like this. Have you tried putting print statements absolutely everywhere to narrow the problem lines down?

It is a selling system, the player clicked on a button that fired the server, there are two buttons one for selling everything in the inventory and the other one to only sell a specific ore. Also my bad I don’t know why i used so many :WaitForChild()

I would throw print statements everywhere. Part of the problem could be that Roblox servers do not load in your character as rapidly as studio does