InputContexts stop receiving inputs if a player's character changes

I’m working on a prop hunt styled game right now and noticed when players become props, all binds break. Events such as pressed, released etc. do not get fired at all.

To repro:

  1. Press F
  2. See “bind pressed” in the output and character model changed.
  3. Press F again.
  4. See nothing happen, no errors, printing or character change.

Repro.rbxl (61.3 KB)

2 Likes

This is not happening to character changes only. This also happens when you force focus on a text box.

Seems you need to setup input action handler each time character added because changing player’s character on server side destroys local character (and thus recreates PlayerGui).
This code works for me:

game.Players.LocalPlayer.CharacterAdded:Connect(function()
	game.Players.LocalPlayer.PlayerGui:WaitForChild('InputContext').InputAction.Pressed:Connect(function()
		print('bind pressed')
		game.ReplicatedStorage.RemoteEvent:FireServer()
	end)	
end)

no_repro.rbxl (61.4 KB)

1 Like

As previously mentioned, this is not a bug since you store the InputContext in PlayerGui (which gets reset when your character changes) but the handler local script is in PlayerScripts (which keeps a reference to the previous InputContext which gets destroyed)

You could just store the InputContext in PlayerScripts as well to fix this

1 Like

The documentation made it quite clear to put them in StarterGui. I had no idea they could also be used in PlayerScripts.

Thanks!

Thanks for pointing this out! Can you link to where in the documentation this is? I’ll get it updated, that advice is outdated now. Actions should be able to live anywhere now.

For some contexts, if you want the UIButton property to work properly, you did have to have your actions inside StarterGui but that bug fix is hopefully rolling out soon.

Thanks

Sure, I found it here Input Action System | Documentation - Roblox Creator Hub.

1 Like

What is this fix going to look like? As far as I know, this is just a fundamental limitation with the way the StarterGui system clones everything. The InputContext tree has to be cloned with the UIButtons its InputBindings reference, so the references stay synced.

I think the best way to solve this issue is to just introduce a property similar to Script.RunContext for ScreenGuis that lets them render anywhere. That way, we can just keep static GUI and IAS trees inside ReplicatedStorage.

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