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

How do I make something happen when a person leaderstats reach a value?

I have a value and I want the script to do something when the value goes up to 40 although I can't figure out how to do it. I started by making a serverscriptservice and made it insert a script into the players script folder which would say

while true do 
wait(1)
local hi = script.Parent,Parent:WaitForChild("leaderstats")
if hi.H == 40 then print("yayayyayay")
end)
end)

After that I deleted the serverscript script and put the player script folder in the starter player script folder. I have tried many other things but the script doesn't work and isn't printing hi my leaderstats is at 40 and no error message is being outputted! I wolud be great-full if someone would help me.

1 answer

✓ Accepted answer

Hello, turquoise_monkeyman!

One way of doing this is using the changed event. This event will fire after a value has changed. The script below will show you how it should look. I hope this fits your request and works out good for you. If you have any errors feel free to reply and let me know!

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:WaitForChild("leaderstats")
	local Value = leaderstats:WaitForChild("YOUR VALUE HERE")
	
	Value.Changed:Connect(function(NewValue)
		if NewValue >= 40 then
			print("epic")
		end
	end)
end)

3 comments

0

Where should I put this script? Thanks for the answer!

0

In a Script inside of ServerScriptService.

0

Thank you so much!

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