I am making a game but this piece of code trigers multiple times in a row and i dont know why. Here is the code:
function dash()
humanoid.WalkSpeed = 200
--Raycasting for wall detection
local params = RaycastParams.new()
params.FilterDescendantsInstances = chr:GetChildren()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.IgnoreWater = true
local ray = workspace:Raycast(humanoid.RootPart.Position,Vector3.new(camera.CFrame.LookVector.X*dash_lenght,torso.Position.Y,camera.CFrame.LookVector.Z*dash_lenght),params)
local to:Vector3
if ray then
to = ray.Position - Vector3.new(camera.CFrame.LookVector.Unit.X*.5,torso.Position.Y,camera.CFrame.LookVector.Unit.Z*.5)
else
to = torso.Position + (camera.CFrame.LookVector*dash_lenght)
end
freeze()
dashing = true
running = false
run_anim:Stop()
humanoid.WalkSpeed = 200
humanoid:MoveTo(to)
dash_anim:Play(.1)
humanoid.MoveToFinished:Connect(function(reached)
unfreeze()
dashing = false
dash_anim:Stop()
humanoid.WalkSpeed = 16
print(dashing) --this triggers more than one
end)
end
game:GetService("RunService").RenderStepped:Connect(function()
if UIS:IsKeyDown(Enum.KeyCode.X) and not dashing then
dash()
end
end)