Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
Thank you! AquausDev 0 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)

Answer this question