Hi everyone,
I’ve been working on a 2D platformer, and a part of that custom movement is the jump. The jump is supposed to go as follows:
While mid-air, the player gets a slight boost upwards while holding jump. This makes it so holding jump gives you slightly floatier physics. This effect is ramped up (higher boost) when running, so your jumps are even floatier when running.
I’ve been recently testing this with my friend. For some reason, only I could have the boosted jump, but for some reason my friend couldn’t. This was also the case when they joined first, and in other scenarios. (For reference, we used Team Test in Studio).
My code can be found below. If anyone has any ideas of how to fix this, please help!
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local jumping = false
local running = false
local leftValue, rightValue = 0, 0
local function onRight(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
leftValue = 1
elseif inputState == Enum.UserInputState.End then
leftValue = 0
end
end
local function onLeft(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
rightValue = 1
elseif inputState == Enum.UserInputState.End then
rightValue = 0
end
end
local function onJump(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
jumping = true
elseif inputState == Enum.UserInputState.End then
jumping = false
end
end
local function onUpdate()
if player.Character and player.Character:FindFirstChild("Humanoid") then
if player.Character == nil then
return
end
if player.Character:FindFirstChild("HumanoidRootPart") == nil then
return
end
player.Character.HumanoidRootPart.AssemblyLinearVelocity -= Vector3.new(0, 0.5, 0)
if jumping then
player.Character.Humanoid.Jump = true
local linVelocity = player.Character.HumanoidRootPart.AssemblyLinearVelocity
player.Character.HumanoidRootPart.AssemblyLinearVelocity += Vector3.new(0, (player.Character.Humanoid.WalkSpeed - 12)/10, 0)
if linVelocity.Y >= 0 then
player.Character.HumanoidRootPart.AssemblyLinearVelocity += Vector3.new(0, 1.35, 0)
end
end
local speed = player.Character.Humanoid.WalkSpeed
if running and player.Character.Humanoid.MoveDirection.Magnitude > 0 then
if speed < 24 then
player.Character.Humanoid.WalkSpeed += 0.075
end
if speed > 24 then
player.Character.Humanoid.WalkSpeed = 24
end
else
if speed > 16 then
player.Character.Humanoid.WalkSpeed -= 0.1
if player.Character.Humanoid.MoveDirection.Magnitude == 0 then
player.Character.Humanoid.WalkSpeed -= 0.05
end
elseif speed < 16 then
player.Character.Humanoid.WalkSpeed = 16
end
end
local moveDirection = rightValue - leftValue
player.Character.Humanoid:Move(Vector3.new(moveDirection,0,0), false)
end
end
local function onRun(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
running = true
elseif inputState == Enum.UserInputState.End then
running = false
end
end
RunService:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, onUpdate)
ContextActionService:BindAction("Left", onLeft, true, "a", Enum.KeyCode.Left, Enum.KeyCode.DPadLeft)
ContextActionService:BindAction("Right", onRight, true, "d", Enum.KeyCode.Right, Enum.KeyCode.DPadRight)
ContextActionService:BindAction("Jump", onJump, true, "w", Enum.KeyCode.Space, Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA, Enum.KeyCode.ButtonB)
ContextActionService:BindAction("Run", onRun, true, Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift, Enum.KeyCode.ButtonX, Enum.KeyCode.ButtonY)