So the script is working but the first time i click the toggle it changes the value to true, but doesnt play the animation, then the second time i click it it does the on animation but the value is set to false, when it should be true.
Video:
https://storage.cloudconvert.com/tasks/4b6f7718-62a5-4292-9dae-78b67ed8a2de/robloxapp-20210813-1003387.webm?AWSAccessKeyId=cloudconvert-production&Expires=1628960798&Signature=CNxtmDCFL%2F4PSeCe3bCk1W2QmcY%3D&response-content-disposition=inline%3B%20filename%3D"robloxapp-20210813-1003387.webm"&response-content-type=video%2Fwebm
(click the link to preview it)
Code:
local switch = script.Parent.holder.thingy
local offpos = UDim2.new(0.03, 0,0.138, 0)
local onpos = UDim2.new(0.6, 0,0.138, 0)
local bg = switch.Parent
local value = switch:WaitForChild("offon")
local ts = game:GetService("TweenService")
value.Value = false
local a = TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0)
local q = TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0)
local off = ts:Create(switch, q, {Position = offpos})
local on = ts:Create(switch, a, {Position = onpos})
local offc = ts:Create(bg, q, {BackgroundColor3 = Color3.fromRGB(255, 2, 100)})
local onc = ts:Create(bg, a, {BackgroundColor3 = Color3.fromRGB(2, 255, 163)})
switch.MouseButton1Click:Connect(function()
if value.Value == false then
off:Play()
offc:Play()
wait(1)
value.Value = true
else
on:Play()
onc:Play()
wait(1)
value.Value = false
end
print(value.Value)
end)