Weird problem with ledge grabbing script

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:

Code:

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

2 Likes

Maybe you could create a variable or attribute that depicts what action you are doing right now, and then playing an animation based on that action?

For example (if you decide to use attributes):

local function vault()
     --I ain't copy n' pasting allat
     character:SetAttribute("State", "Vaulting")
end

local function Climb(ray)
     --I ain't copy n' pasting allat
     character:SetAttribute("State", "Climbing")
end

Character.AttributeChanged:Connect(function(attribute)
     if character:GetAttribute("State") == "Vaulting" then
          vaultAnim:Play() --or whatever it is
     elseif character:GetAttribute("State") == "Climbing" then
          climbAnim:Play() --you get the idea
     end
end)

--Character being your character / player
1 Like

Good idea but it didnt quite work the same exact thing happened. new code:

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
	
	char:SetAttribute("State", "Vaulting")
	
	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

	char:SetAttribute("State", "Climbing")

	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")
						char:SetAttribute("State", "LetGo")
						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("W pressed")
					
					char:SetAttribute("State", "Accel")

					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
		
		char:SetAttribute("State", "Holding")
		
		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
	repeat
	hrp.CFrame = hrp.CFrame:Lerp(vis.CFrame,0.4)
		wait()
		rp = rp + 1
		until rp == 5
		hrp.CFrame = vis.CFrame
		
		
		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)



char.AttributeChanged:Connect(function(attribute)
	if char:GetAttribute("State") == "Vaulting" then
		smallVaultAnim:Play() 
		letGoAnim:Stop()
		idleAnim:Stop()
		climbAnim:Stop()
	elseif char:GetAttribute("State") == "Climbing" then
		climbAnim:Play()
		letGoAnim:Stop()
		idleAnim:Stop()
		smallVaultAnim:Stop()
	elseif char:GetAttribute("State") == "Holding" then
		idleAnim:Play()
		letGoAnim:Stop()
		climbAnim:Stop()
		smallVaultAnim:Stop()
	elseif char:GetAttribute("State") == "HoistUp" then
		smallVaultAnim:Play()
		idleAnim:Stop()
		letGoAnim:Stop()
		climbAnim:Stop()
	elseif char:GetAttribute("State") == "Accel" then
		smallVaultAnim:Play()
		idleAnim:Stop()
		letGoAnim:Stop()
		climbAnim:Stop()
	elseif char:GetAttribute("State") == "LetGo" then
		idleAnim:Stop()
		letGoAnim:Play()
		climbAnim:Stop()
		smallVaultAnim:Stop()
		
		
	elseif char:GetAttribute("State") == "noneother" then
		idleAnim:Stop()
		letGoAnim:Stop()
		climbAnim:Stop()
		smallVaultAnim:Stop()
	end
end)



--[[

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)
]]--
1 Like

Does it work if you wait a bit before doing it again or does it only do it when you do it rapidly. If it only happens when you do it rapidly, it might be something with task.delay or task.wait. In other cases, the only think I can recommend is that the animations have a higher priority than the regular roblox animations.

1 Like

I put some prints inside of the area where it plays the animations and if you switch ledges while your in the air it does the accel one like normal but once you attach to the ledge it doesnt print the holding state again like it does the first time you hold onto a ledge, i dont know if that made sense

1 Like

Maybe the boolean for holding isn’t changing somewhere, causing it not to play the animation again?

1 Like

thats not the error inside of the second check and in the holding area im not even checking for holding wihch would make it impossible for it to be that also i checked other places and tryed setting it to false inside of the second check

1 Like

To be honest, I’m pretty much out of ideas for now, hope you manage to find the solution though!

1 Like

I fixed it, all it took was changing a return to this
hum.AutoRotate = false
char:SetAttribute(“State”, “Holding”)

now if you dont mind me im gonna go cry

1 Like

nevermind it was even easier than that all i really needed to do was put a task.delay(.1,function() inside the check if next function because it was calling the hold if theyre was a valid wall before it was registering that the player was pressing w so it was calling hold then immediately after that calling hoistup therefore canceling out the hold idle animation

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.