I'm trying to make a part that when is touched it will make another part 4 studs in front of it (x), and if that part is touched will do the same thing, basically i'm trying to make a endless path that goes on forever if you try to go walk in that path.
But.. i just can't think of anything! my script will make a instance if the part is touched but that's it, i wanted to make that instance if touched will also make another instance with the same function.
local function touched () local part = script.Parent:Clone() local position = script.Parent.Position part.Position = position + Vector3.new(0,0.5,4) -- what do i put here or outside of this function to make it that if the instance is touched it will do the same thing again and again? end script.Parent.Touched:Connect(touched)
You can do this by using a recursive function that will just call itself when a new part has been touched.
function waitForTouch (part) local connection; connection = part.Touched:Connect(function(hit) if hit and hit.Parent:FindFirstChildOfClass("Humanoid") then connection:disconnect(); local newPart = part:Clone(); newPart.CFrame = CFrame.new(newPart.CFrame.p + Vector3.new(0,0,4)) newPart.Parent = part.Parent; part:Destroy() waitForTouch(newPart) end end) end waitForTouch(workspace.Part)
This will create a new part and destroy the old one.