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

How do I make this onTouch function repeat, if the While True Do function doesn't work?

Asked by 10 years ago

The below works, but the script stops working after one go, because it isn't told to keep repeating itself.

print 'Mud path loaded...'
local FP = script.Parent
local SP = script.Parent.Parent.StayingPart
time1 = (1) --time before falls after step
time2 = (2) --time before regenerates
SPPos = SP.Position
SPFrame = SP.Rotation


    function onTouch(part)
        wait(time1) 
        FP.Anchored = false
        wait(time2)
        FP.Anchored = true
        FP.Position = SPPos
        FP.Rotation = SPPos
    end 

    FP.Touched:connect(onTouch)

However, it seems that the While True Do breaks the script.

print 'Mud path loaded...'
local FP = script.Parent
local SP = script.Parent.Parent.StayingPart
time1 = (1) --time before falls after step
time2 = (2) --time before regenerates
SPPos = SP.Position
SPFrame = SP.Rotation

 while true do
    function onTouch(part)
        wait(time1) 
        FP.Anchored = false
        wait(time2)
        FP.Anchored = true
        FP.Position = SPPos
        FP.Rotation = SPPos
    end 

    FP.Touched:connect(onTouch)

end

I have tried moving the second 'end' before the 'FP.Touched:connect(onTouch)', yet to no avail. Suggestions and help, please? I used to be a good programmer, but League of Legends forced it all right outta my brain. xD

1 answer

Log in to vote
0
Answered by 10 years ago

Nevermind, I think I've got it.

Ad

Answer this question