So, I have a menu GUI system. Its not really good (but some games do use the same system, so whatever), but I do have a problem and it occurred when it was added to the game.
See, I just disable the controls of the player when they go into the menu, and re-enable them when they leave. However, I have noticed that when people reset, their controls get disabled. Only solution is to go into menu and then back out. I’ve put print statements whenever I make calls to enable/disable controls, but nothing happens when the player is reset. Any ideas on how to fix? (by reset I mean killed in any way: health to 0, admin commands, reset, etc)
Also, while you are telling me, how can you enable/disable resetting on the fly, if that is at all possible.
Have you tried that when a character spawns, running the code that you use when you exit the menu (the line/s of code used to make the player move again)? Also if you want to disable resetting in general just use this in a LocalScript:
game:GetService("StarterGui"):SetCore("ResetButtonCallback", false)
How would I detect that the character has spawned in but isn’t entering the menu? If I just do it when the character spawns, then they could possibly be able to move depending on which code gets executed first: The one that is in the loading screen that locks their character, or the one that is in the script that detects when they spawn. Also, how would I know when they spawned? Would I add a script in StarterPlayer or something of the sort?
If the player has spawned is pretty easy to do (server script in ServerScriptService):
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(chr)
--Code For it here.
end)
end)
also if you want to wait till after the loading screen you can always have a wait() or something similar to make it happen after that.
I tried, but it just says infinite yield possible and never actually works. Here’s my code:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(chr)
local controls = require(player:WaitForChild("PlayerScripts").PlayerModule):GetControls()
controls:Enable()
print("controls enabled")
end)
end)```
I’m having the same problem. Has anyone found a solution yet?
Yep I am too, was there a solution?
Hello! I am sorry for the late reply but yes, I did find a solution. How to Disable Player Movement - #2 by H_mzah
I ended up figuring it out but thank you.
I answer a bit late, but I know why this is happening. When the script that imports the controls is destroyed, for some reason the controls are set to “Disabled”. However screenguis have the “ResetOnSpawn” property enabled by default. So when the player respawns, the script in the gui is removed and therefore the controls are corrupted. A possible solution would be to put the gui script outside the gui itself (starterplayerscripts for example) or to deactivate the reset on spawn property of the screen gui (if this option is deactivated, the screen gui will remain as it is after the spawning of the player. So it’s up to you to use the humanoid.Died event to be able to deactivate the gui when the player dies)
TL:DR → When the script is deleted, the controls are corrupted. The ResetOnSpawn property of screen guis is responsible for this problem.