Hello, I am making a toggle script that is supposed to make my other script Enabled/Disabled depending on if the setting is turned on/off, however, for some reason, my script stays disabled after you turn it the setting off
local onoff = true
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0)
local bar = script.Parent.BarBackground.Bar
script.Parent.BarBackground.Button.MouseButton1Click:Connect(function()
if onoff == true then
onoff = false
script.Parent.PlayerHider.Enabled = true
ts:Create(bar,ti, {BackgroundColor3 = Color3.fromRGB(163, 68 , 68)}):Play()
bar.TextLabel.Text = "Off"
bar:TweenPosition(UDim2.new(0.5,0,0.5,0), "InOut", "Quad", 0.5, true)
else
onoff = true
script.Parent.PlayerHider.Enabled = false
ts:Create(bar,ti, {BackgroundColor3 = Color3.fromRGB(195, 226, 197)}):Play()
bar.TextLabel.Text = "On"
bar:TweenPosition(UDim2.new(0,0,0.5,0), "InOut", "Quad", 0.5, true)
end
end)
basically if I explained it badly, once I try to click the button while the text says On, it’ll say it has turned Off but the script is still enabled. Please Help
Video of my problem:
PlayerHider script:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local function SetCharacterTransparency(character)
for i, descendant in ipairs(character:GetDescendants()) do
if not descendant:IsA("BasePart") then
continue
end
descendant.Transparency = 1
end
end
for i, player in ipairs(Players:GetPlayers()) do
if player == LocalPlayer then
continue
end
player.CharacterAdded:Connect(function(character)
if not player:HasAppearanceLoaded() then
player.CharacterAppearanceLoaded:Wait()
end
SetCharacterTransparency(character)
end)
if not player.Character then
continue
end
SetCharacterTransparency(player.Character)
end
Any Help is appreciated, thank you!