Line of code won't work

I have a part to take the cheese from a player when they run through it but it does everything but add the cheese number and clear the backpack. No the output is no help it doesn’t say there is an error in the code or anything


Note: the print statements are to help me try to find the problem(where the code quits working)

If CheeseCollected is an ObjectValue; try changing it to IntValue if you want the values to be numbers (i.e CheeseCollected = 1)

i already set it to be numbers with the “#plr.Backpack:GetChildren()” being the number to add and the “CheeseCollected.Value” being a number value

Then maybe do more debugging- I can’t seem to figure out the issue.

script.Parent.Touched:Connect(function(hit)
    local character = hit.Parent
    if character:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(character)
        if plr then 
            print(plr.Parent)
            local CheeseCollected = game:GetService("ReplicatedStorage").RoundInfo.CheeseCollected
            CheeseCollected.Value = CheeseCollected.Value + #plr.Backpack:GetChildren()
            plr.Backpack:ClearAllChildren()
            print("Cleared?")
        end
    end
end)

Btw, next time you make a devforum post; dont screenshot your code and post it; instead copy and paste it and format it with 3 backticks (i.e you insert 3 backticks, ``` and your line of code then end it with 3 backticks again)

ok… been at it for hours so i might just rewrite the whole script

Good luck rewriting the script; and make sure that you try to rewrite it completely in a different way than what you’ve done in the previous script. You could use Remote Events etc, but that’s up to you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.