What is going wrong with my script?

Hello,

I have came here because there is something wrong with my sliding script.
[video-to-gif output image]
I’ve used references from:

There are no related errors being returned. This script was obtained through searching version history. Mind you that this script worked before.

uis = game:GetService("UserInputService")
local Tool = script.Parent
local plr = game:GetService("Players")
local char = plr.LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")
local lastTime = tick()
anim = hum:LoadAnimation(game.ReplicatedStorage.Animations.PrimarySprint)
local RootPart = char:WaitForChild("HumanoidRootPart")
local RollTrack = hum:LoadAnimation(game.ReplicatedStorage.Animations:WaitForChild("SlideAnimation"))
repeat wait() until RollTrack.Length ~= 0
local RollStartTime = 0
local RollDirection = Vector3.new()
local RollMult = 25/RollTrack.Length
local DB = false
local Sliding = false
local TweenService = game:GetService("TweenService")

wait(.75)
char.Humanoid.WalkSpeed = 15
hum.JumpPower = 37

-- Offset Function
function ChangeCameraOffset(Offset)
	if not char then char = plr.Character or plr.CharacterAdded:Wait() end
	local Humanoid = char:WaitForChild("Humanoid")

	local Tween = TweenService:Create(Humanoid, TweenInfo.new(0.1), {CameraOffset = Offset})
	Tween:Play()
end

-- Sprint
uis.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift and Sliding == false then
		anim:Play()
		char.Humanoid.WalkSpeed = 30
		uis.MouseIconEnabled = false
	end
end)

uis.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		char.Humanoid.WalkSpeed = 15
		anim:Stop()
		uis.MouseIconEnabled = false
	end
end)

-- Slide Function
local LastBeat = tick()

game:GetService("RunService").Heartbeat:Connect(function()
	local dT = tick()-LastBeat
	LastBeat = tick()

	if tick()-RollStartTime < .75 then
		RootPart.CFrame = CFrame.new(RollDirection*dT*RollMult) * RootPart.CFrame
	end
	
	if Sliding == true then
		ChangeCameraOffset(Vector3.new(0, -2, 0))
		hum.JumpPower = 0
	else
		ChangeCameraOffset(Vector3.new(0, 0.475, 0))
		hum.JumpPower = 37
	end
end)

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.LeftShift and uis:IsKeyDown(Enum.KeyCode.C) and DB == false and tick()-RollStartTime > .75 and hum.MoveDirection.Magnitude > 0 then
		anim:Stop()
		Sliding = true
		RollTrack:Play()
		RollStartTime = tick()
		local dirVec = workspace.CurrentCamera.CFrame.LookVector
		RollDirection = (dirVec*Vector3.new(1,0,1)).unit
		DB = true
		RollTrack:Stop()
		wait(1)
		Sliding = false
		wait(1)
		DB = false
	end
end)

Please tell me what is happening. Thanks!

Could you describe the issue of how its not working so we know what we’re looking for?

That’s the issue, I can’t identify it. It doesn’t return errors.

What do you mean by that? Is it not playing? Is it not doing what you intended it to do? Like what exactly is the issue you want to be solve?

Regardless if something doesn’t display an error and still isn’t working, just drop a few prints under every if statement and/or loop. See what prints and what doesn’t to narrow down the issue.

Yes, The animation is not playing and the sprint is not either. The sprint by itself works, but when accompanied by the sliding script, it completely breaks. I have been adding prints, but for the sake of connivence, I’ve removed them for your viewing sake.

Could you re-add the prints → then post the new script with prints and screenshot the output

Screen Shot 2021-03-05 at 8.50.52 PM

print("start")
uis = game:GetService("UserInputService")
local Tool = script.Parent
local plr = game:GetService("Players")
local char = plr.LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")
local lastTime = tick()
anim = hum:LoadAnimation(game.ReplicatedStorage.Animations.PrimarySprint)
local RootPart = char:WaitForChild("HumanoidRootPart")
local RollTrack = hum:LoadAnimation(game.ReplicatedStorage.Animations:WaitForChild("SlideAnimation"))
repeat wait() until RollTrack.Length ~= 0
local RollStartTime = 0
local RollDirection = Vector3.new()
local RollMult = 25/RollTrack.Length
local DB = false
local Sliding = false
local TweenService = game:GetService("TweenService")

print("variables")
wait(.75)
char.Humanoid.WalkSpeed = 15
hum.JumpPower = 37

print("character ajustments")
function ChangeCameraOffset(Offset)
	if not char then char = plr.Character or plr.CharacterAdded:Wait() end
	local Humanoid = char:WaitForChild("Humanoid")

	local Tween = TweenService:Create(Humanoid, TweenInfo.new(0.1), {CameraOffset = Offset})
	Tween:Play()
end

print("camera function")
uis.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift and Sliding == false then
		anim:Play()
		char.Humanoid.WalkSpeed = 30
		uis.MouseIconEnabled = false
	end
end)

uis.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		char.Humanoid.WalkSpeed = 15
		anim:Stop()
		uis.MouseIconEnabled = false
	end
end)

print("sprint")
local LastBeat = tick()

game:GetService("RunService").Heartbeat:Connect(function()
	local dT = tick()-LastBeat
	LastBeat = tick()

	if tick()-RollStartTime < .75 then
		RootPart.CFrame = CFrame.new(RollDirection*dT*RollMult) * RootPart.CFrame
	end
	
	if Sliding == true then
		ChangeCameraOffset(Vector3.new(0, -2, 0))
		hum.JumpPower = 0
	else
		ChangeCameraOffset(Vector3.new(0, 0.475, 0))
		hum.JumpPower = 37
	end
end)

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.LeftShift and uis:IsKeyDown(Enum.KeyCode.C) and DB == false and tick()-RollStartTime > .75 and hum.MoveDirection.Magnitude > 0 then
		anim:Stop()
		Sliding = true
		RollTrack:Play()
		RollStartTime = tick()
		local dirVec = workspace.CurrentCamera.CFrame.LookVector
		RollDirection = (dirVec*Vector3.new(1,0,1)).unit
		DB = true
		RollTrack:Stop()
		wait(1)
		Sliding = false
		wait(1)
		DB = false
	end
end)
print("end")

It seems some variables are not passing the prints

Does it only print “start”? Does it not print “variables”? or character adjustments?

No,

print("start")
uis = game:GetService("UserInputService")
print("1")
local Tool = script.Parent
print("2")
local plr = game:GetService("Players")
print("3")
local char = plr.LocalPlayer.Character
print("4")
local hum = char:WaitForChild("Humanoid")
print("5")
local lastTime = tick()
print("6")
anim = hum:LoadAnimation(game.ReplicatedStorage.Animations.PrimarySprint)
print("7")
local RootPart = char:WaitForChild("HumanoidRootPart")
print("8")
local RollTrack = hum:LoadAnimation(game.ReplicatedStorage.Animations:WaitForChild("SlideAnimation"))
print("9")
repeat wait() until RollTrack.Length ~= 0
print("10")
local RollStartTime = 0
print("11")
local RollDirection = Vector3.new()
print("12")
local RollMult = 25/RollTrack.Length
print("13")
local DB = false
print("14")
local Sliding = false
print("15")
local TweenService = game:GetService("TweenService")
print("16")

The prints end at 9:
Screen Shot 2021-03-05 at 8.55.31 PM

well this is your issue then. The condition is prob not being met and since its a loop, its just yielding the thread forever.

Yes, I’m currently looking into that. It prints end. But the sliding does not work. The animations, the camera, nothing works. Only sprint & animations.

Well remove the loop and repeat the process. Note you don’t have to put a print under every single line. Just put prints under anything that can yield (loops, waitForChild(), etc) and all conditional statements (if statements, etc). You can remove the old prints so they don’t clutter the output.

Try to put a few prints inside your InputBegan and inputEnded connections. One right after you make the connection (so you know its running) and one right after the if statement (to see if the condition is met)