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

[SOLVED] attempt to index nil with 'leaderstats'?

script.Parent.Main.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	
	player.leaderstats.Cashl.Value = player.leaderstats.Cashl.Value + 1 -- the error line.
end)

1 answer

✓ Accepted answer

literally three seconds later i found out i had "game.Players.LocalPlayer"

here is the fix lol:

-- Normal script:

script.Parent.GiveCash.OnServerEvent:Connect(function()
	local player = script.Parent.Parent.Parent
	local Debounce = false
	
	if Debounce == false then
		Debounce = true
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
		wait()
		Debounce = false
	end

end)

-- Local script:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.GiveCash:FireServer()
end)

that was because "game.Players.LocalPlayer" is nil to the server.

https://devforum.roblox.com/t/attempt-to-index-nil-with-leaderstats/530935

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