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

Why doesn't this script adder work every 10 stages = Skips + 1?

It says this whenever i test it.

Workspace.LeaderStats.StatsAddition:1: attempt to index field 'LocalPlayer' (a nil value)

Script 'Workspace.LeaderStats.StatsAddition', Line 1

THOSE 2 ERRORS?

Stage1 = game.Players.LocalPlayer.PlayerStats:WaitForChild("Stage")

Stage1.Value.Changed:connect(function(plr)
		local PlayerStats = plr:WaitForChild("PlayerStats")
		local Stage = PlayerStats:WaitForChild("Stage")
		local Skips = PlayerStats:WaitForChild("Skips")
	
	if Stage.Value % 10 == 0 then
    	Skips.Value = Skips.Value + 1
	end
end)

THIS IS SUPPOSED TO GIVE 1 SKIP PER EVERY 10 STAGES...

1 answer

✓ Accepted answer

You're not using a Local Script

You seem to not be using a Local Script. Local Player can only work in Local Scripts.

Still doesn't work?

This is because Local Scripts don't work in workspace.

My suggestion would be to use a Regular Script, because Local Scripts can't change Values with FE. I also saw that you were using the Changed Event on the Value, not the Instance. Don't do that.

Solution

Use a Regular Script, and get the players with the PlayerAdded event. This will work with FE and without. This is probably the best solution.

game.Players.PlayerAdded:connect(function(plr)
	plr:WaitForChild("PlayerStats"):WaitForChild("Stage")
	Stage1.Changed:connect(function()
		local PlayerStats = plr:WaitForChild("PlayerStats")
		local Stage = PlayerStats:WaitForChild("Stage")
		local Skips = PlayerStats:WaitForChild("Skips")
		
		if Stage.Value % 10 == 0 then
			Skips.Value = Skips.Value + 1
		end
	end)
end)
Also, on the changed event, it doesn't give you the player. The changed event gives you the property that was changed. You should also use the Changed Event on the Instance, not the Properties of the Instance.

Good Luck!

If I helped, please don't forget to accept my answer.

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