Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

only one keybinded localscript runs unless another is turned off?

Im having problems trying to get two keybinded controls working together, this is the first one, its in a localscript:

local player = game.Players.LocalPlayer
local char = player.Character
local space = game.Workspace
local animal = space:WaitForChild(char.Name.."2")




local ContextActionService = game:GetService("ContextActionService")
function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("button pressed")
		
		animal.Vitals.Heart.Control.ForwardTrig:FireServer()
		script.Parent.StopW.Disabled = false
		wait()
		script.Disabled = true
	end
end
 
ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.W)



and this is the second one:

local player = game.Players.LocalPlayer
local char = player.Character
local space = game.Workspace
local animal = space:WaitForChild(char.Name.."2")




local ContextActionService = game:GetService("ContextActionService")
function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("button pressed")
		
		animal.Vitals.Heart.Control.BackwardTrig:FireServer()
		script.Parent.StopS.Disabled = false
		wait()
		script.Disabled = true
	end
end
 
ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.S)

both scripts turn on when the key is down and activate a stopping localscript to stop an action when the key is released. if one script is enabled and the other is disabled, the enabled script runs, and vice versa. however if both are enabled only one will respond, the other will not fire unless the other is turned off.

1 answer

✓ Accepted answer

In both of your scripts you're binding a function called 'keyPress' try renaming them so they aren't the same

This discussion is preserved as it was. New answers, comments, and votes are closed.