So i got this script that when a bool value changes from true to false, vise versa, itll do something, but it works wrong and just ends up doing it 100 times and not even stop on the right one? I hope this makes sense lol
wait(1)
local park = script.Parent.InPark
script.Parent.InPark.Changed:Connect(function()
print("got parkevent")
if park.Value == true then --park
script.Parent.Center.Anchored = true
park.Value = false
print("anchor center")
else
if park.Value == false then --unpark
script.Parent.Center.Anchored = false
park.Value = true
print("unanchored center")
end
end
end)
The .Changed event fires each time the value changes, and you’re changing the value inside the function, so that’s probably causing it to loop forever.
Why do you need to set park to false here, if its supposed to be parked? Try removing park.Value = false and park.Value = true and just change the value with some other method
wait(1)
local park = script.Parent.InPark
dog = true
script.Parent.InPark.Changed:Connect(function(NewValue)
print("got parkevent")
if dog == true then --park
script.Parent.Center.Anchored = true
park.Value = false
dog = false
print("anchor center")
elseif dog == false then --unpark
script.Parent.Center.Anchored = false
park.Value = true
dog = true
print("unanchored center")
end
end)
Youre basically doing the same thing here. Are you trying to make a parking system for a car? You could change park with a button instead of switching the value right after parking and unparking. Or if you want to anchor it and quickly unanchor it, you could simply do that without changing the value.
yeah basically i made it so when the driver gets out, this is what happens, so its basically just anchoring and unanchoring it, but i have no clue where else to start