Hi, I wrote 2 scripts, and to make it easier for me in the future, I want these 2 scripts to merge into one, but I’m not quite getting it right. Separately they work fine, but as soon as I try to combine them nothing works, please help me.
These two scripts:
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
while true do
humanoid.Jump = true
wait(1)
end
local function onKeyPress(player, input)
if input.KeyCode == Enum.KeyCode.Space or input.UserInputType == Enum.UserInputType.Touch and input.KeyCode == Enum.KeyCode.ButtonA then
return Enum.ContextActionResult.Sink
end
end
game:GetService("ContextActionService"):BindAction("DisableJump", onKeyPress, false, Enum.KeyCode.Space, Enum.KeyCode.ButtonA)
Im pretty sure the first script, to use the players character, must be server sided, yet the second one requires key input, which must be client side. right?
No, I just checked and it doesn’t work in StarterPlayer. Well i mean i made these 2 scripts and put them in StarterCharacter and they both work, but i can’t make them in one
If you are putting the 2nd script below the while true loop it will never run since the while true loop doesn’t end, so the code stays stuck on that loop.
To end it you use break whenever you want that loop to stop. Or you could put the function and binding above the loop, or you could run the loop in a different thread using task.spawn(function() end) or coroutines.
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
task.spawn(function()
while true do
humanoid.Jump = true
wait(1)
end
end)
local function onKeyPress(player, input)
if input.KeyCode == Enum.KeyCode.Space or input.UserInputType == Enum.UserInputType.Touch and input.KeyCode == Enum.KeyCode.ButtonA then
return Enum.ContextActionResult.Sink
end
end
game:GetService("ContextActionService"):BindAction("DisableJump", onKeyPress, false, Enum.KeyCode.Space, Enum.KeyCode.ButtonA)
The forum rules states you can’t ask people to make scripts for you, however they can make a short example breaking it down, like I did: All I had to do was add a task.spawn so that the loop wouldn’t mess with the code after.