Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a GUI Button make a Disabled Local Script From StarterCharacterScript = True?

Asked by 5 years ago
Edited 5 years ago

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)
0
you have to make a script first and then paste it in and select it and click the lua changer thing and the community will help you fix it until it works. ncano 22 — 5y
0
I see. Thanks KingCrebz 3 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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.

Ad

Answer this question