What do you want to achieve?
I want to have a button which toggles ‘enable’ for a GUI, for mobile users
What is the issue?
The button works fine, however, whenever a player resets character, the buttons disappear.
What solutions have you tried so far?
I have attempted various ways of using BindAction with different functions, but as mentioned, it works fine for as long as a character is not reset.
The code I have is pretty much ‘vanilla’ code. I have the LocalScript in StarterPlayer->StarterPlayerScripts and am wondering whether that is the issue?! If this is the issue, where would I need to put it?
As per documentation, the StartPlayerScripts run only once ,in the beginning. Could this be the issue on why when a player resets their character, the buttons disappear?
Here is my code (hopefully it’s formatted fine):
local LocalPlayer = game.Players.LocalPlayer local PlayerGui = LocalPlayer:WaitForChild("PlayerGui") local contextAction = game:GetService("ContextActionService") local ReplicatedFirst = game:GetService("ReplicatedFirst") local function onBKeyPress(actionName, userInputState, inputObject) local platform = ReplicatedFirst:WaitForChild("Platform", 10) if userInputState == Enum.UserInputState.Begin then if platform.PC.Value == true then PlayerGui.ShopGui:FindFirstChild("PC_ShopGui").Enabled = not PlayerGui.ShopGui:FindFirstChild("PC_ShopGui").Enabled elseif platform.Mobile.Value == true then PlayerGui.ShopGui:FindFirstChild("Mobile_ShopGui").Enabled = not PlayerGui.ShopGui:FindFirstChild("Mobile_ShopGui").Enabled end end end contextAction:BindAction("keyPressB", onBKeyPress, true, Enum.KeyCode.B)
Thank you for the help!