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

BoolValue.Changed:Connect(function() - NOT WORKING?

Asked by 5 years ago

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!

01wait(1)
02 
03 
04game.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)
0
Don't use polling. DeceptiveCaster 3761 — 5y
0
I have no clue what polling is ???? Primrose_Studio 53 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

01local var = workspace:WaitForChild("VAR")
02local watertime = var:WaitForChild("watertime")
03local union = script.Parent
04 
05watertime.Changed:Connect(function(isTrue)
06    if isTrue then
07        for i = 1, 64 do
08            wait(0.1)
09            union.Position = union.Position + Vector3.new(0, 0.5, 0)
10        end
11    end
12end)

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.

0
So why wasn't it working before ? Primrose_Studio 53 — 5y
0
Mainly because of line 11, where you tried to set the part's position by giving it a CFrame. The code I gave you also omitted parts of your code that weren't necessary for it to run. LukeSmasher 619 — 5y
Ad

Answer this question