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!

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)
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.

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.

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