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

Attempt to index nil with 'leaderstats'?

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

✓ Accepted answer

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)

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