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
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.
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?
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.