Hey, I Have this script which makes a part in workspace set it’s transparency to 1/0 after each time it’s clicked. It works, but after I try to make the part invisible again by clicking on textbutton it just fades away for a millisecond and then comes back right after. Here’s the script:
local clicked = false
if not clicked then
script.Parent.MouseButton1Click:Connect(function()
game:GetService("TweenService"):Create(workspace.Union, TweenInfo.new(0.25, Enum.EasingStyle.Sine), {Transparency = 0}):Play()
game.Workspace.Union.Transparency = 1
end)
clicked = true else
game:GetService("TweenService"):Create(workspace.Union, TweenInfo.new(0.25, Enum.EasingStyle.Sine), {Transparency = 0}):Play()
script.Parent.MouseButton1Click:Connect(function()
game.Workspace.Union.Transparency = 0
end)
clicked = false
end
Hi, so the problem is that there are two functions calling when the mouse is clicked for the second time. What you should do is put everything under a single MouseButton1Click function. It should look like this:
local clicked = false
script.Parent.MouseButton1Click:Connect(function()
if not clicked then
game:GetService("TweenService"):Create(workspace.Union, TweenInfo.new(0.25, Enum.EasingStyle.Sine), {Transparency = 0}):Play()
game.Workspace.Union.Transparency = 1
clicked = true
else
game:GetService("TweenService"):Create(workspace.Union, TweenInfo.new(0.25, Enum.EasingStyle.Sine), {Transparency = 0}):Play()
game.Workspace.Union.Transparency = 0
clicked = false
end
end)
Hmm, Still doesn’t work. The same problem remains. The first time I click the textbutton it sets transparency to 0. But when I click it again it does this: