Hello, Im trying to make a GUI Button that make a Disabled Local Script turn to Enabled. But my scripting sucks. Nothing i made didn't work. Please help me. Im thankful to you.
local TextButton = script.Parent.Parent.Parent LocalScript = script.Parent.Parent.LocalScript function onClick() if LocalScript.Disabled == false then LocalScript.Disabled = true elseif LocalScript.Disabled == true then LocalScript.Disabled = false end end Button.MouseButton1Click:connect(onClick)
Local Script (this change would be on the Client only)
local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil and workspace:FindFirstChild(player.Name) ~= nil local TextButton = script.Parent.Parent.Parent LocalScript = player.Character.LocalScript TextButton.Activated:Connect(function(onClick) if LocalScript.Disabled == false then LocalScript.Disabled = true elseif LocalScript.Disabled == true then LocalScript.Disabled = false end end)
ISSUES
A. Make sure that your variables are correctly named in your script (you defined TextButton, but used "Button" to connect the function)
B. Use Activated
rather than MouseButton1Click
since Activated
works for all devices, not just computers
C. The LocalScript
from StarterPlayerScripts
will be parented under the player's Character
, so that's the definition to index
D. Player Characters load before they are placed into the workspace
, so you have to wait for it to be in the workspace before it is used in the script
E. Make sure that the TextButton
is under the StarterGui
in some way, unless you are directly parenting it to the PlayerGui
via a Script
.