Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Clicking union for cash script waitforchild problem, how do I solve it?

So few things you need to know

  • When you click a union it is supposed to give you 1 "Money"
  • I already have a leaderboard script in the game
  • It works on solo studio but not in a server, so I added a Wait for child, but it still doesn't work. I'm not sure how to fix it so I came upon this site and asked this question. Here is the script:
local Clicked = script.Parent:WaitForChild("ClickDetector")
Clicked.MouseClick:Connect(function(player)
	game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 1
end)

1 answer

✓ Accepted answer

you create the stats from another script, so here it may not have loaded. waitforchild on the stats

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    local stats = plr:WaitForChild(“leaderstats”)
    if stats then 
        local money = stats:FindFirstChild(“Money”)
        if money then
            money.Value = money.Value + 1
        end
    end
end)

4 comments

0

also are you using a Script or a LocalScript? You can not access the “LocalPlayer” property from a Script. ONLY

0

LocalScripts can access LocalPlayer, and never make a LocalScript a descendant of workspace unless under a Script

0

Thank you for your assistance, I had a feeling that it wasn't connected. Script works well now.

0

And I was using a script earlier, not a local script

This discussion is preserved as it was. New answers, comments, and votes are closed.