Hello, I am trying to make a long jump script that is basically supposed to emulate the long jump mechanic in Super Mario 64, but its been hard trying to make one that’s pixel perfect.
Basically, Im making a state
string, that is supposed to check the current humanoid string and return its value to a text label thats connected to a billboard element on the players head, then change the Text labels text.
But the issue is that, in any state, I can do a long jump, I can spam the long jump, prompting me to get more airtime, and the long jump also doesn’t even apply a correct force when I do spam the long jump. ( LShift + Spacebar ). There isn’t any errors, so I came here to ask for help.
So how can I fix this?
--\\ Variables //--
repeat task.wait() until game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Character = game.Players.LocalPlayer.Character
local JumpAnimation = Character.Humanoid:LoadAnimation(RS.LongJumpAnimation.LongJumps)
local DView = 70
local Table = {}
local root = script.Parent.PrimaryPart
local humanoid = root.Parent:WaitForChild("Humanoid")
local state = " "
local stateText = script.Parent:WaitForChild("Head"):FindFirstChildOfClass("BillboardGui").TextLabel
--\\ Functions //--
function speedWatch(speed)
if speed == 24 then
local boostVal = 1.25
return boostVal
elseif speed == 16 then
local boostVal = 1.15
return boostVal
else
local boostVal = 1
return boostVal
end
end
humanoid.Running:Connect(function(speed)
if speed == 16 then
state = "WALKING"
elseif speed == 0 then
state = "IDLE"
else
if speed == 24 then
state = "RUNNING"
end
end
end)
humanoid.Jumping:Connect(function()
state = "JUMPING"
end)
local Deb = false
UIS.InputBegan:Connect(function(Input, IsTyping)
if state == "RUNNING" and state ~= "IDLE" or state ~= "JUMPING" or state ~= "LONG_JUMP" then
if IsTyping then return end
if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and UIS:IsKeyDown(Enum.KeyCode.Space) and humanoid.Running then
if not Deb then
Deb = true
state = "LONG_JUMP"
local speed = Character.Humanoid.WalkSpeed
local speedBoost = speedWatch(humanoid.WalkSpeed)
JumpAnimation:Play()
humanoid.Jump = false humanoid.JumpPower = 0
root:ApplyImpulse(root.CFrame.LookVector * (1000 * speedBoost))
workspace.Gravity = 145.8
root:ApplyImpulse(root.CFrame.YVector * (475 * speedBoost))
task.wait(0.25)
workspace.Gravity = 196.2
humanoid.Jump = false humanoid.JumpPower = 50
JumpAnimation:Stop()
Deb = false
end
end
end
end)
--\\ Loops //--
while task.wait() do
stateText.Text = "STATE: "..state
print(state)
end