I’m making a ledge grabbing system and im having an error where when i transfer to a different part the animations stop. video showing problem:
wait(.5)
local plr = game.Players.LocalPlayer
local char = plr.Character
local cas = game:GetService("ContextActionService")
local checking = false
local uis = game:GetService("UserInputService")
local holding = false
local nextLedge = false
local animator = char:WaitForChild("Humanoid"):WaitForChild("Animator")
local smallVaultAnim = animator:LoadAnimation(script.SmallVault)
local hoistAnim = animator:LoadAnimation(script.Hoist)
local letGoAnim = animator:LoadAnimation(script.LetGo)
local leftAnim = animator:LoadAnimation(script.Left)
local rightAnim = animator:LoadAnimation(script.Right)
local idleAnim = animator:LoadAnimation(script.Idle)
local climbAnim = animator:LoadAnimation(script.Climb)
local switchSide = nil
--[[
local vis = Instance.new("Part")
vis.Parent = char.Parent
vis.Color = Color3.new(1, 0, 0.0156863)
vis.Size = Vector3.new(0.5,0.5,0.5)
vis.Shape = Enum.PartType.Ball
vis.Transparency = 0.6
vis.Anchored = true
vis.CanCollide = false
vis.Name = "VisualizationSphere"
----------------------------------- anchor player ------------------------------------------
local att = Instance.new("Attachment")
att.Name = "LinearVelocityAtt"
local lv = Instance.new("LinearVelocity")
lv.Name = "FreezeLV"
lv.Parent = att
att.Parent = hrp
lv.Enabled = true
lv.MaxForce = math.huge
lv.VectorVelocity = hrp.Position
]]--
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
function vault(ray)
local vis = Instance.new("Part")
vis.Parent = char.Parent
vis.Color = Color3.new(1, 0, 0.0156863)
vis.Size = Vector3.new(0.5,0.5,0.5)
vis.Shape = Enum.PartType.Ball
vis.Transparency = 0.6
vis.Anchored = true
vis.CanCollide = false
vis.Name = "VisualizationSphere"
print("vault")
local y = (ray.Instance.Size.Y/2 - char:WaitForChild("Torso").Size.Y/2)
vis.CFrame = CFrame.new(ray.Position.X, y + ray.Position.Y, ray.Position.Z) * CFrame.new(Vector3.new(), Vector3.new() - ray.Normal)
hrp.CFrame = hrp.CFrame * CFrame.new(0,0.5,0)
local bv = Instance.new("BodyVelocity")
bv.Parent = hrp
bv.MaxForce = Vector3.new(10000,10000,10000)
bv.Velocity = hrp.CFrame.LookVector * 30 + hrp.CFrame.UpVector * 20
smallVaultAnim:Play()
idleAnim:Stop()
leftAnim:Stop()
rightAnim:Stop()
hoistAnim:Stop()
letGoAnim:Stop()
climbAnim:Stop()
task.delay(0.15,function()
bv:Destroy()
end)
task.delay(0.4,function()
vis:Destroy()
checking = false
end)
end
function Climb(ray)
local vis = Instance.new("Part")
vis.Parent = char.Parent
vis.Color = Color3.new(1, 0, 0.0156863)
vis.Size = Vector3.new(0.5,0.5,0.5)
vis.Shape = Enum.PartType.Ball
vis.Transparency = 0.6
vis.Anchored = true
vis.CanCollide = false
vis.Name = "VisualizationSphere"
local att = Instance.new("Attachment")
att.Name = "LinearVelocityAtt"
local lv = Instance.new("LinearVelocity")
lv.Name = "FreezeLV"
lv.Attachment0 = att
lv.Parent = att
att.Parent = hrp
lv.Enabled = true
lv.MaxForce = math.huge
lv.VectorVelocity = Vector3.new(0,0,0)
vis.CFrame = CFrame.new(ray.Position.X,ray.Position.Y,ray.Position.Z) * CFrame.new(Vector3.new(),Vector3.new() - ray.Normal)
local rp = 0
game.Players.LocalPlayer.Character:WaitForChild("WallClimbing").Value = true
smallVaultAnim:Stop()
print("climbstop")
idleAnim:Stop()
leftAnim:Stop()
rightAnim:Stop()
hoistAnim:Stop()
letGoAnim:Stop()
climbAnim:Play()
hum.AutoRotate = false
repeat
hrp.CFrame = hrp.CFrame:Lerp(vis.CFrame,0.2)
wait()
rp = rp + 1
until rp == 5
task.delay(0.5,function()
att:Destroy()
end)
task.delay(0.2,function()
vis:Destroy()
game.Players.LocalPlayer.Character:WaitForChild("WallClimbing").Value = false
checking = false
hum.AutoRotate = true
hrp:ApplyImpulse(-hrp.CFrame.UpVector * 2)
end)
end
function checkIfNext()
local rayparams = RaycastParams.new()
rayparams.FilterType = Enum.RaycastFilterType.Exclude
rayparams.FilterDescendantsInstances = {char}
local nrDir = game.Workspace.CurrentCamera.CFrame.LookVector * 7
local nrOrg = char:WaitForChild("Head").Position
local nextRay = workspace:Raycast(nrOrg,nrDir,rayparams)
if char.Parent:FindFirstChild("VisualizationSphere") then
char.Parent:FindFirstChild("VisualizationSphere")
end
if nextRay and nextRay.Distance <= 10 then
print("dawg")
print(nextRay.Distance)
print("cw")
nextLedge = true
Hold(nextRay)
checking = true
task.delay(0.5,function()
nextLedge = false
end)
elseif nextRay and nextRay.Distance >= 10.1 then
print("next")
nextLedge = false
elseif not nextRay then
print("even farther")
nextLedge = false
end
end
function Input(vis,att)
local input ; input = uis.InputBegan:Connect(function(key)
if holding == true then
if key.KeyCode == Enum.KeyCode.S then
if hoistAnim.IsPlaying == false then
if checking == true then
game.ReplicatedStorage.Remotes.CanSprintOn:FireServer()
game.ReplicatedStorage.Remotes.CanCrouchOn:FireServer()
input:Disconnect()
if game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart"):FindFirstChild("LinearVelocityAtt") then
game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart"):WaitForChild("LinearVelocityAtt"):Destroy()
end
print("Down")
idleAnim:Stop()
letGoAnim:Play()
game.Players.LocalPlayer.Character:WaitForChild("WallGrabbing").Value = false
hrp:ApplyImpulse(-hrp.CFrame.UpVector * 2)
task.delay(0.2,function()
vis:Destroy()
holding = false
checking = false
hum.AutoRotate = true
end)
end
end
end
if key.KeyCode == Enum.KeyCode.W then
if smallVaultAnim.IsPlaying == false then
input:Disconnect()
checkIfNext()
att:Destroy()
print("newcew")
if idleAnim.IsPlaying == true then
idleAnim:Stop()
end
smallVaultAnim:Play()
hum.AutoRotate = true
local bv = Instance.new("BodyVelocity")
bv.Name = "LocalBodyVelocity"
bv.Parent = hrp
bv.MaxForce = Vector3.new(10000,10000,10000)
bv.Velocity = workspace.CurrentCamera.CFrame.LookVector * 30 + workspace.CurrentCamera.CFrame.UpVector * 20
game.ReplicatedStorage.Remotes.CanSprintOn:FireServer()
game.ReplicatedStorage.Remotes.CanCrouchOn:FireServer()
task.delay(0.1,function()
bv:Destroy()
end)
task.delay(0.4,function()
if nextLedge == false then
holding = false
checking = false
game.Players.LocalPlayer.Character:WaitForChild("WallGrabbing").Value = false
hrp.CFrame = char:WaitForChild("Torso").CFrame
smallVaultAnim:Stop()
end
end)
task.delay(.4,function()
print(nextLedge)
if nextLedge == false then
if game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart"):FindFirstChild("LinearVelocityAtt") then
print("Dieeeeee")
game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart"):WaitForChild("LinearVelocityAtt"):Destroy()
end
vis:Destroy()
holding = false
checking = false
hum.AutoRotate = true
elseif nextLedge == true then
return
end
end)
end
end
end
if checking == false and holding == false then
if att then
att:Destroy()
print("stop")
idleAnim:Stop()
if vis then
vis:Destroy()
end
end
end
end)
end
function Hold(ray)
if hrp:FindFirstChild("LocalBodyVelocity") then
hrp:FindFirstChild("LocalBodyVelocity"):Destroy()
end
if hrp:FindFirstChild("LinearVelocityAtt") then
hrp:FindFirstChild("LinearVelocityAtt"):Destroy()
end
local vis = Instance.new("Part")
vis.Parent = char.Parent
vis.Color = Color3.new(1, 0, 0.0156863)
vis.Size = Vector3.new(0.5,0.5,0.5)
vis.Shape = Enum.PartType.Ball
vis.Transparency = 0.6
vis.Anchored = true
vis.CanCollide = false
vis.Name = "VisualizationSphere"
print("So Far so good")
local y = (ray.Instance.Size.Y/2 + vis.Size.Y/2)
vis.CFrame = CFrame.new(ray.Position.X, y + ray.Instance.CFrame.Position.Y + -0.6, ray.Position.Z) * CFrame.new(Vector3.new(), Vector3.new() - ray.Normal)
local dist = (hrp.Position - vis.Position).Magnitude
print(dist)
if dist <= 10 then
print("Still Going")
holding = true
game.ReplicatedStorage.Remotes.CanSprintOff:FireServer()
game.ReplicatedStorage.Remotes.SprintingOff:FireServer()
game.ReplicatedStorage.Remotes.CanCrouchOff:FireServer()
game.ReplicatedStorage.Remotes.CrouchOff:FireServer()
game.Players.LocalPlayer.Character:WaitForChild("WallGrabbing").Value = true
smallVaultAnim:Stop()
leftAnim:Stop()
rightAnim:Stop()
hoistAnim:Stop()
letGoAnim:Stop()
idleAnim:Play()
climbAnim:Stop()
print("Creating")
local att = Instance.new("Attachment")
att.Name = "LinearVelocityAtt"
local lv = Instance.new("LinearVelocity")
lv.Name = "FreezeLV"
lv.Attachment0 = att
lv.Parent = att
att.Parent = hrp
lv.Enabled = true
lv.MaxForce = math.huge
lv.VectorVelocity = Vector3.new(0,0,0)
local rp = 0
hum.AutoRotate = false
idleAnim:Play()
repeat
hrp.CFrame = hrp.CFrame:Lerp(vis.CFrame,0.4)
wait()
rp = rp + 1
until rp == 5
hrp.CFrame = vis.CFrame
if idleAnim.IsPlaying == false then
idleAnim:Play()
end
Input(vis,att)
end
end
function check()
if checking == false then
if holding == false and char:WaitForChild("WallClimbing").Value == false then
checking = true
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
local lrOrg = char:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,-1,0)
local lrDir = char:WaitForChild("HumanoidRootPart").CFrame.LookVector * 2
local lowerRay = workspace:Raycast(lrOrg,lrDir,params)
local mrOrg = char:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,2,0)
local mrDir = char:WaitForChild("HumanoidRootPart").CFrame.LookVector * 2
local middleRay = workspace:Raycast(mrOrg,mrDir,params)
local urOrg = char:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,6,0)
local urDir = char:WaitForChild("HumanoidRootPart").CFrame.LookVector * 2
local upperRay = workspace:Raycast(urOrg,urDir,params)
if lowerRay and not upperRay and not middleRay then
print("Vault")
vault(lowerRay)
elseif lowerRay and middleRay and not upperRay then
print("Hold")
Hold(middleRay)
elseif lowerRay and middleRay and upperRay then
print("Climb")
Climb(upperRay)
elseif not lowerRay and middleRay and upperRay then
print("Climb")
Climb(upperRay)
elseif not lowerRay and not upperRay and not middleRay then
task.delay(0.2,function()
checking = false
end)
else
task.delay(0.2,function()
checking = false
end)
end
end
end
end
cas:BindAction("CheckForLedge",check,false,Enum.KeyCode.Space)
--[[
function switchLedgeSide()
if holding and switchSide ~= nil then
holding = false
nextLedge = true
if switchSide == "right" then
leftAnim:Play()
elseif switchSide == "left" then
rightAnim:Play()
end
switchSide = nil
end
end
local actionName = "CheckForVault"
local actionId = "rbxassetid://5036198620"
cas:BindAction(actionId, function(_, state, input)
if state == Enum.UserInputState.Begin and input.KeyCode == Enum.KeyCode.E then
check()
end
end, false, Enum.KeyCode.E)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
task.delay(0.2, function()
switchLedgeSide()
end)
end
end)
]]--
im aware its a mess but i think the problem happens in the input function because if you switch between ledges it prints out “W pressed” before and after you switch to the new ledge and I dont know if theyre are any ways around this because I dont have alot of Experience with Uis. anything would help
i honestly feel kinda dumb because it seems like its going to be the easiest solution