Long Jump Script Not Working

So I have a long jump script that is supposed to make the player jump forward, like in super Mario games, and when I press F, nothing happens. Here’s the code.

local m = game.Players.LocalPlayer:GetMouse()
db = true
m.KeyDown:connect(function(k)
	k = k:lower()
	if k == "f" then
		if db == true then
			db = false
			script.Part.BodyPosition:Clone().Parent = script.Parent.HumanoidRootPart
			wait()
			script.Parent.HumanoidRootPart.BodyPosition.Position = game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").Attachment.WorldPosition
			local animTrack = script.Parent.Humanoid:LoadAnimation(script.Animation)
			animTrack:Play()
			wait(0.5)
			script.Parent.HumanoidRootPart.BodyPosition:Destroy()
			wait(0.5)
			db = true
		end
	end
end)

I’d appreciate some help with this.

Mouse.KeyDown is deprecated. I strongly recommend you start adapting to the new UserInputService service. UserInputService | Documentation - Roblox Creator Hub

Using UserInputService.InputBegan replaces Mouse.KeyDown and adds a lot more flexibility on detecting player input.

So then what do I replace KeyDown with?

local UIS = game:GetService("UserInputService")
db = true
UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
local key == input.KeyCode
	if key == Enum.KeyCode.F then
		if db == true then
			db = false
			script.Part.BodyPosition:Clone().Parent = script.Parent.HumanoidRootPart
			wait()
			script.Parent.HumanoidRootPart.BodyPosition.Position = game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").Attachment.WorldPosition
			local animTrack = script.Parent.Humanoid:LoadAnimation(script.Animation)
			animTrack:Play()
			wait(0.5)
			script.Parent.HumanoidRootPart.BodyPosition:Destroy()
			wait(0.5)
			db = true
		end
	end
end
end)
2 Likes

Still doesn’t work.image

I got new code that actually works, I just need an animation to play when I do it.

local UIS = game:GetService("UserInputService")
		
UIS.InputBegan:connect(function(input,gameProcessedEvent)
	if gameProcessedEvent then return end --If player is typing return
	if input.UserInputType == Enum.UserInputType.Keyboard then --If player is using a KeyBoard
		if input.KeyCode  == Enum.KeyCode.Z then -- Connects when the key is touched
		    		local force = Instance.new("BodyVelocity")
	force.velocity =  Vector3.new(0,80,0) 
	force.Parent = script.Parent.Torso
	force.velocity =  (script.Parent.Torso.CFrame.lookVector * 120)  + Vector3.new(0, 60,0)
	wait(.1)
	force:Destroy()
			wait()--Change Z to key you want
			print(player.Name .. ' pressed a key')
	   	end
	end
end)
1 Like