Zipline doing things it's not supposed to (Repeating)

Hello there,

I recently tried to make a zipline, it’s 99% done but I have one error which I’m getting very sick of!

The issue:

As you see, once I’m on the zipline the zipline will repeat forever.

Workspace:

Seat Script:

seat = script.Parent
anim = seat.Animation
proximityPrompt = script.Parent.Parent.Parent.Parent.ProximityPrompt.ProxPromptPart.ProximityPrompt

function Added(Descendant)
	if (Descendant.ClassName == "Weld") then
		local Humanoid = Descendant.Part1.Parent:FindFirstChild("Humanoid")

		if Humanoid ~= nil then
			local plr = Humanoid
			game.Workspace.ZiplineCode.bindableEvent.ziplineEvent:Fire(plr)
			Animation = Humanoid:LoadAnimation(anim)
			Animation:Play()
		end
	end
end

function Removing(Descendant)
	if Animation ~= nil then
		Animation:Stop()
		Animation:Remove()
	end
end

seat.ChildAdded:Connect(Added)
seat.ChildRemoved:Connect(Removing)

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		proximityPrompt.Enabled = false
	else
		proximityPrompt.Enabled = true
	end

end)

ProximityPrompt Script:

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	local hum = plr.Character:WaitForChild("Humanoid")
	
	script.Parent.Parent.Parent.MainSeat.ZiplineSeat.Seat:Sit(hum)
end)

Tweening zipline script:

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Destinations = game.Workspace.ZiplineCode.DestinationNavigation
local AIZipline = game.Workspace.ZiplineStructure.MainSeat.ZiplineSeat

local NewPoint = 1
local Speed = 25

local debounce = false

AIZipline.PrimaryPart = AIZipline.Center
AIZipline:SetPrimaryPartCFrame(AIZipline.Center.CFrame)

function GetTime(Distance, Speed)
	local Time = Distance / Speed
	return Time
end

function WeldAIZipline()
	for i = 1, #AIZipline:GetChildren() do
		if AIZipline:GetChildren()[i] ~= AIZipline.PrimaryPart then
			local Weld = Instance.new("WeldConstraint")
			Weld.Part0 = AIZipline:GetChildren()[i]
			Weld.Part1 = AIZipline.PrimaryPart
			Weld.Parent = AIZipline.PrimaryPart

			AIZipline:GetChildren()[i].Anchored = false
		end
	end
end

function AutoZipline()
	NewPoint += 1
	
	if not Destinations:FindFirstChild(""..NewPoint) then
		if game.Workspace.ZiplineStructure.MainSeat.ZiplineSeat.Seat:FindFirstChild("SeatWeld") then
			local hum = game.Workspace.ZiplineStructure.MainSeat.ZiplineSeat.Seat.SeatWeld.Part1.Parent:WaitForChild("Humanoid")
			hum.Jump = true
			warn("At end, we jump. Source: 'Humanoid'")
		end
		wait(2)
		NewPoint = 1
		AIZipline.PrimaryPart.CFrame = Destinations:FindFirstChild("1").CFrame
		wait(2)
	end

	local NextPoint = Destinations[""..NewPoint]
	local Distance = (AIZipline.PrimaryPart.Position - NextPoint.Position).Magnitude
	local Time = GetTime(Distance, Speed)
	
	warn(Time.." time. Source: '"..script.Name.."'")

	local TweenInformation = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

	local Tween = TweenService:Create(AIZipline.PrimaryPart, TweenInformation, {CFrame = NextPoint.CFrame})
	Tween:Play()
	Tween.Completed:Wait()

	AutoZipline()

end

game.Workspace.ZiplineCode.bindableEvent.ziplineEvent.Event:Connect(function()
	
	warn("Received signal")
	WeldAIZipline()
	warn("Welded AI Zipline")
	AutoZipline()
	warn("Tweening AI Zipline")
	
end)

Any help is very appreciated, thank you!

1 Like

it infinitely repeats because AutoZipline is recursive. At the end of AutoZipline you call it again:

1 Like

I tried removing that, but then the entire script breaks and nothing will work.

I tried “ignoring” and “removing” those lines, but:

If I remove the:

  • Tween.Completed:Wait()
  • What happens: Script will immediately go back to repeating.

If I remove the:

  • AutoZipline()
  • What happens? The script breaks and nothing will happen.

Any more fixes?

the if not Destinations:FindFirstChild(""..NewPoint) then condition appears to be handling when a zipline has completed traveling. It jumps the sitting humanoid, resets NewPoint then repositions the AIZipline back at the start.

The rest of the logic that moves the zipline will still execute after that condition is handled; starting from the top of the zipline as if NewPoint += 1 resolved to 1. I’m guessing you maybe want that to be an if else conditional, so it handles both at the end and not at the end, seperately.


-- finish ziplining if at end
if not Destinations:FindFirstChild(""..NewPoint) then
    if game.Workspace.ZiplineStructure.MainSeat.ZiplineSeat.Seat:FindFirstChild("SeatWeld") then
        local hum = game.Workspace.ZiplineStructure.MainSeat.ZiplineSeat.Seat.SeatWeld.Part1.Parent:WaitForChild("Humanoid")
        hum.Jump = true
        warn("At end, we jump. Source: 'Humanoid'")
    end
    wait(2)
    NewPoint = 1
    AIZipline.PrimaryPart.CFrame = Destinations:FindFirstChild("1").CFrame
    wait(2)

else -- otherwise continue ziplining 
    local NextPoint = Destinations[""..NewPoint]
    local Distance = (AIZipline.PrimaryPart.Position - NextPoint.Position).Magnitude
    local Time = GetTime(Distance, Speed)

    warn(Time.." time. Source: '"..script.Name.."'")

    local TweenInformation = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

    local Tween = TweenService:Create(AIZipline.PrimaryPart, TweenInformation, {CFrame = NextPoint.CFrame})
    Tween:Play()
    Tween.Completed:Wait()

    AutoZipline() -- I think you meant for this to be recursive
end

Wow! It works!

Thank you so much for assisting me.
Have a wonderful day <3

1 Like