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

Set points to 0 when level changes?

I've been trying to do this for a while now and I can't seem to get it right. The script I made is most likely horribly off. The code is place in StarterPlayerScripts, it's supposed to reset the points back to 0 when your level changes. I've rewrote the code several times and I failed every time.

Basic Code:

function Change()

	script.Parent.Parent.leaderstats.Points.Value = 0
	
end

Change()
script.Parent.Parent.leaderstats.Level.Value.Changed:connect(Change)

1 answer

✓ Accepted answer

You're close.


Basically, leaderstats.Level.Value is a number. You can't do 5.Changed:Connect(.... That doesn't work. You have to use .Changed on the Instance itself.


Also, you should probably make sure you're using a regular script, and the script should be placed inside ServerScriptService. This means we'll need to get the player a different way. I suggest .PlayerAdded

-- script in SSS

-- NOTE: It'd be easiest to just do this in the script where you make the leaderstats, but this will work too.

game.Players.PlayerAdded:Connect(function(plr)
	
	local leaderstats = plr:WaitForChild("leaderstats")
	local level = leaderstats:WaitForChild("Level")
	local points = leaderstats:WaitForChild("Points")

	level.Changed:Connect(function(val)
		points.Value = 0
	end)
end)

Let me know if that works for you!

1 comment

0

It worked, thank you!

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