Hey. How do you make a script inside of a textButton so every time the textbutton is clicked it disables/enabes a script in starterpack?
Here:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Backpack = Player/WaitForChild("Backpack")
local LocalScript = Backpack.MyLocalScript
local Button = script.Parent
local function OnButtonClick()
LocalScript.Disabled = not LocalScript.Disabled
end
Button.MouseButton1Click:Connect(OnButtonClick)
This will just set the local script’s current disabled state to the opposite of what it currently is
local button = script.Parent
enabled = true
local script = game.StarterPack.Script
button.MouseButton1Click:Connect(function()
if enabled == true then
enabled = false
script.Disabled = true
else
enabled = true
script.Disabled = false
end
end)
There’s just a few things I wanna clear up here:
-
If you are enabling/disabling a script in StarterPack, on the client, that will do nothing, since the client won’t receive those changes because that script when they joined was cloned to their backpack, and if this was on the server, it’ll only update for users that joined after the changes
This can easily be shortened to:
script.Disabled = not script.Disabled
Yeah, I Already moved the script into startercharacter. Still can’t resolve the issue tho. Here, I pasted this script in the textbutton of the gui
local textbutton = script.Parent
enabled = true
local script = script.Parent.Script
textbutton.MouseButton1Click:Connect(function()
if enabled == true then
enabled = false
script.Parent.AudioVisualizer.Disabled = true
else
enabled = true
script.Parent.AudioVisualizer.Disabled = false
end
end)
You don’t need that variable at all:
Also your variable name can’t be script
as that already has a meaning in roblox
local textbutton = script.Parent
local theScript = script.Parent.Script
textbutton.MouseButton1Click:Connect(function()
theScript.Disabled = not theScript.Disabled
script.Parent.AudioVisualizer.Disabled = theScript.Diabled and false or true
end)
I See, What is “TheScript” though? I really don’t know what any of this means haha, Can you tell me how this script works and which line is the one that locates the script that gets disabled/enabled? (the script that needs to be enabled/disables is in StarterPlayerScripts)
Continuing off of what they said, I believe “theScript” is a variable that you should change to the respective location of your script
I don’t think you can disable scripts from local scripts
Scripts inside the StarterCharacter
container won’t execute.
That is a modified version of your script. The script is referencing the variable you had called script
I renamed it since script
is part of luau syntax