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

How to properly unbind an action (User Input Service)?

game.ReplicatedStorage.UpdateControls.OnClientEvent:Connect(function(binds)
	--unbind current controls
	game:GetService("ContextActionService"):UnbindAction("jumpAction")
	--bind new
	local event = UIS.InputEnded:connect(function(input)
		if input.KeyCode == Enum.KeyCode[binds.Jump] then
		jumpfunc()
		elseif input.KeyCode == Enum.KeyCode[binds.Crouch] then
			crouchfunc()
				elseif input.KeyCode == Enum.KeyCode[binds.Prone] then
			pronefunc()
		end
	end)

My code is above. binds is a table of the binds, returned when the controls are updated/on start. My issue is, when the new controls are set, the old ones still work as well.

1 comment

0

Why are you changing the keybinds with a remote event? Isn't that supposed to be something stored by each client? Why are you unbinding using ContextActionService and binding with UserInputSevice?

2 answers

[SOLVED] Instead of connecting every time on the remoteevent, i connected once and just updated a table.

Hey there. I would normally bind each function to its own input ended event. Try see if that works.

4 comments

0

Then what? How do you disconnect them after that?

0

You’d want to use InputBegan first and then InputEnded after that. This is useful if you want to detect a key press or keyhold

0

Ok, so I bind them all to their own event. What do I do when I update the controls to make them unbind?

0

This didn't help at all. Solved it myself.

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