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!
01 | wait( 1 ) |
02 |
03 |
04 | game.Workspace.VAR.watertime.Changed:Connect( function () |
05 | print ( "sup" ) |
06 | while true do |
07 | if game.Workspace.VAR.watertime.Value = = true then |
08 | print ( "Im so loved" ) |
09 | for i = 1 , 64 do |
10 | wait( 0.1 ) |
11 | script.Parent.Position = CFrame.new( 0 ,script.Parent.Position+ 0.5 , 0 ) |
12 | end |
13 | else |
14 | print ( "nous" ) |
15 | wait( 1 ) |
16 | end |
17 |
18 |
19 | end |
20 | 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.
01 | local var = workspace:WaitForChild( "VAR" ) |
02 | local watertime = var:WaitForChild( "watertime" ) |
03 | local union = script.Parent |
04 |
05 | watertime.Changed:Connect( function (isTrue) |
06 | if isTrue then |
07 | for i = 1 , 64 do |
08 | wait( 0.1 ) |
09 | union.Position = union.Position + Vector 3. new( 0 , 0.5 , 0 ) |
10 | end |
11 | end |
12 | 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.