I need to combine two scripts into one

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)
3 Likes

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?

If not, what solutions have you tried so far?

I don’t know what you’re talking about, I wrote it all down in the LocalScript and added it in StarterCharacterScripts

Which solutions have you tried already for combining them?

just added 1 script to another script and that’s it, just trying it out, lol :smile:

I might be wrong, but I think the keypress script has to be in StarterPlayer, not StarterCharacter

(i must go afk for a while, apologies)

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.

man, I don’t understand anything, I’m not a scriptwriter :smile:, if you can, please write a script.

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.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.