Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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)
0
also are you using a Script or a LocalScript? You can not access the “LocalPlayer” property from a Script. ONLY satanxd666 60 — 6y
0
LocalScripts can access LocalPlayer, and never make a LocalScript a descendant of workspace unless under a Script satanxd666 60 — 6y
0
Thank you for your assistance, I had a feeling that it wasn't connected. Script works well now. warfighter10000 4 — 6y
0
And I was using a script earlier, not a local script warfighter10000 4 — 6y
Ad

Answer this question