In my script, I'm trying to make a union move up 0.5 every 0.1 seconds. (Might change that later). I use CFrame.new, and I'm using a for i=1, 64 loop to make it repeat and so I can track the new position of the part. I have a pre-made physical variable in the workspace in a folder called VAR, the variable is a BoolValue and it is called watertime. However, when I use .Changed , the script doesn't run at all. I've tried it with while loops and looked at RemoteEvents, but I just can't get my head around RemoteEvents. The code is attached below, I would be incredibly thankful if you could help!
wait(1) game.Workspace.VAR.watertime.Changed:Connect(function() print("sup") while true do if game.Workspace.VAR.watertime.Value==true then print("Im so loved") for i=1,64 do wait(0.1) script.Parent.Position=CFrame.new(0,script.Parent.Position+0.5,0) end else print("nous") wait(1) end end end)
I don't know what purpose that while true
loop serves, but assuming I'm understanding what you're trying to do correctly, you don't need it.
local var = workspace:WaitForChild("VAR") local watertime = var:WaitForChild("watertime") local union = script.Parent watertime.Changed:Connect(function(isTrue) if isTrue then for i = 1, 64 do wait(0.1) union.Position = union.Position + Vector3.new(0, 0.5, 0) end end end)
Line 5: .Changed returns the new value, which I've named 'isTrue'
Line 6: if isTrue then
is the same as if watertime.Value == true then
Line 9: You only need to do union.Position + Vector3.new(0, 0.5, 0)
to add 0.5 onto the Y axis each iteration. CFrame involves rotation too, which isn't involved in what you're trying to do, so Position will suffice.