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

How could I convert this script to only run when the value is changed instead of using a while loop?

Asked by 4 years ago

Instead of looping forever is there a way I could only run this code if script.WORLD_OFFSET.Value changes?

while true do 
    wait()
    WORLD_OFFSET = script.WORLD_OFFSET.Value --Vector3.new(0, 0, 0)
    LOCAL_OFFSET = script.LOCAL_OFFSET.Value -- Vector3.new(2, 3, 9.5)
end

3 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You can use GetPropertyChangedSignal. Using .Changed can also be applied in this situation, however will fire without a target property–it will fire whenever anything changed, be it Name, or any other property, you’ll always have to hone down on what was modified which can be tedious or cause further issues. With GetPropertyChangedSignal, you can pass which property you wish to listen to, and receive what changed still too!

local WORLD_OFFSET = script.WORLD_OFFSET

WORLD_OFFSET:GetPropertyChangedSignal("Value"):Connect(function(New)
    print(New)
end)
Ad
Log in to vote
0
Answered by 4 years ago
local WORLD_OFFSET = script.WORLD_OFFSET

WORLD_OFFSET.Changed:Connect(function()
    --Code
end
Log in to vote
0
Answered by 4 years ago

omg you people are over complicating everything. its easy

game.workspace.numvalue.Changed:Conenct(function()
if game.workspace.numvalue.Value == 1 then
print("1")
end)

Answer this question