Okay so lets say for example I want a script to fire when a number value hits 4 and something happens
so what I would want to achieve here is a script that checks the number values value and when it detects that the values is 4 and fires the scripts
this is something I wrote that checks for the number value
local NumberValue = workspace.NumberValue
if NumberValue.Value == 4 then
--do stuff
end
What I think the problem may be is the script checks once, sees that the number value isn’t 4 and goes to sleep, any tips on making it work?
You can use the GetPropertyChangedSignal() event (or event the Changed event) to detect when a value changes.
Here is your code:
local NumberValue = workspace:WaitForChild("NumberValue")
NumberValue:GetPropertyChangedSignal("Value"):Connect(function()
if NumberValue.Value == 4 then
-- your stuff
end
end)
it shouldn’t be used if you want to change a NumberValue’s Value property
local NumberValue = workspace:WaitForChild("NumberValue")
NumberValue:GetPropertyChangedSignal("Value"):Connect(function()
if NumberValue.Value == 4 then
-- your stuff
end
end)
local NumberValue = workspace:WaitForChild("NumberValue")
NumberValue.Changed:Connect(function()
if NumberValue.Value == 4 then
-- your stuff
end
end)
because of how NumberValues work, these two scripts work the exact same way
local NumberValue = workspace:WaitForChild("NumberValue")
NumberValue.Changed:Connect(function()
if NumberValue.Value == 4 then
RemoteEvent:FireServer()
end
end)
EDIT: I still had that script in a quote for some reason