My zipline system only works once and i can't figure out why

So I’ve been working on a zipline system for my parkour game for a while now, however I noticed that it can only be used once before the prompt just ends up doing absolutely nothing, I cannot for the life of me figure this out.

local Attachment1 = script.Parent.Parent.Attachment1
local Attachment2 = script.Parent.Parent.Parent.Parent.End.Top.Attachment2
local Distance = (Attachment1.WorldPosition - Attachment2.WorldPosition).Magnitude
local Time = Distance/35

script.Parent.Triggered:Connect(function(Player)
	print("Start")
	local OnZipline = true
	
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	
	local Animation = Humanoid.Animator:LoadAnimation(script.Animation)
	
	HumanoidRootPart.Anchored = true
	
	local RootPosition, TargetPos = HumanoidRootPart.Position, Attachment2.WorldPosition
	HumanoidRootPart.CFrame = CFrame.new(RootPosition, Vector3.new(TargetPos.X, RootPosition.Y, TargetPos.Z))
	
	HumanoidRootPart.Position = Attachment1.WorldPosition - Vector3.new(0,2,0)
	Animation:Play()
	print("Hm")
	
	local Tween = game:GetService("TweenService"):Create(HumanoidRootPart,TweenInfo.new(Time,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{Position = Attachment2.WorldPosition - Vector3.new(0,2,0)})
	Tween:Play()
	
	Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
		if Humanoid then
			print(Humanoid.Jump)
			if Humanoid.Jump == true then
				if OnZipline then
					Tween:Cancel()
					JumpOffZipline(Player,Tween,Animation,OnZipline)
				end
			end
		end 
	end)
	
	wait(Time)
	Tween:Cancel()
	JumpOffZipline(Player,Tween,Animation,OnZipline)
end)

function JumpOffZipline(Player,Tween,Animation,Onzip)
	local Character = Player.Character
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	HumanoidRootPart.Anchored = false
	Animation:Stop()
	Onzip = false
end

Here’s a clip of what happens (the cut is just me climbing back up):
https://gyazo.com/3db8eec6325ae7542815847b6d043d2e

any help would be greatly appreciated

Can anyone else use it after it’s been used once? Meaning if you test with two players, and player 1 uses it, can player 2 use it after?

1 Like

The problem is that you are changing the local value of onZip in your JumpOffZipline function which does not change the value in where it was called. You could move your OnZipline declaration to the top of your file and just use that variable and don’t pass it into your function. That should fix things.

If this code is used by multiple players you may need to add a variable in the player to keep track of it.

1 Like

If you respawn your character, would the zipline be usable once more?

1 Like

Other players are able to use it after, but also just once

I was thinking this too, but OnZipLine is a local variable that only exists in the triggered:connect function, and would get re-declared and set to true again anyway the next time the prompt is triggered wouldn’t it? So he doesn’t even really need to set it back to false?

1 Like

yeah you’re able to use it again if you reset

Does “start” print at least when you try to use the prompt again?

1 Like

Quakage has suggested that the JumpOffZipline function should be relocated above all of that.

1 Like

the point of it is to prevent the code for jumping off the zipline from running again after leaving it

Upon my initial observation of the code, I believed this could be the problem as you are not disconnecting it once it’s completed.

1 Like

thats what the variable is for, the actual jumping off part only runs if the variable is set to true

Yes, but still it’ll keep running every time they jump.

1 Like

any ideas on how to counter that? if i remove it that means the player will be stuck on the zipline the whole time which i imagine would get annoying

Here is how you can fix it from running over and over.

Of course move the disconnection to where it needs to be disconnected.

1 Like

i added that in with no errors, but sadly the problem is still there

Are you able to answer what drumzart said?

When you are unable to use the zipline again, does the prompt print out?

1 Like

Have you relocated this function above the trigger function?

1 Like

yeah i have done both of these

Okay second time is the charm. It appears it is a problem with using the Position of the HumanoidRootPart. I switched it to use the CFrame and it worked.

1 Like