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

Anyway to check if a value in the player has changed?

Hello, I'm trying to see if the level has changed somehow, and below is the only one I can think of and it doesn't work. Any ideas to fix this script or a new script to do this? (The script is in the LocalPlayer and the 'stats' is in the player)

while true do
	local old_level = game.Players.LocalPlayer:FindFirstChild("stats").Level
	wait(.1)
	local current_level = game.Players.LocalPlayer:FindFirstChild("stats").Level
	if current_level.Value > old_level.Value then
		print("worked")
		script.Parent.Display.Visible = true
		return
	end
end

2 answers

Use the changed event.

local player = game.Players.LocalPlayer
local value = player:FindFirstChild("stats").Level

value.Changed:Connect(function(property)
	print(property)
end)

It's worth noting this doesn't work with properties, only the actual value/instance.

1 comment

0

Thank you!

Try this.

local player = game.Players.LocalPlayer
local value = player:FindFirstChild("stats").Level
local value2 = value.Value

value.Changed:Connect(function()
    if value2 ~= player:FindFirstChild("stats").Level.Value then
		local NewValue = player:FindFirstChild("stats").Level.Value
		print("The old value "..value2.." has changed to ".. NewValue)
	end
end)

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