Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.