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

Attempt to index nil with 'leaderstats'?

Asked by 2 years ago

script.Parent.MouseButton1Down:Connect(function(hit) local player = game.Players:FindFirstChild(hit.parent.Name) player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10 script.Parent.Visible = false

i want to make button that spawn part for 100$ but for test i coded button gives u 10$ but didnt work

1 answer

Log in to vote
0
Answered by
ryanzhzh 128
2 years ago

Next time use a lua button, and remote events.

-- Errors:--

Atleast make sure to use player:WaitForChild("leaderstats")

This player.leaderstats.Cash.Value + 10 will not replicate to the server. You need that for the stats to change for every client (user)

-- Tips

Use game.Players.LocalPlayer instead of that game.Players:FindFirstChild(hit.parent.Name)

-- Extra: --

Use the code example 1 below with a local script!

-- Code example 1, button script: --

script.Parent.MouseButton1Click:Connect(function()
    local player = game.Players.LocalPlayer
    game.Re
end)

-- Code example 2, remote event script: --

script.Parent.OnServerEvent:Connect(function(player)
    player.leaderstats.Cash.Value += 10
end)
Ad

Answer this question