I am working on a script which allows you to turn a model transparent, and visible
with just one button, thought I am just having one issue, once I set the boolean on = true, it just goes onto the next if statement, and I want to break out of the execution of the script.
My layout of the model of which the part I want to turn transparent and visible are.
Heres the layout of the button which I click.
I have already tried putting the break function after the declaration of the boolean in the first if statement.
Thanks for taking time and helping!
And obviously if there’s a stupidly misspelled word or anything like that, please do let me know!
You have too many connections. You (typically) shouldn’t have connections within other connections for the same type of connection. Clicking the detector should perform what you want based off the variable (on) then change the variable afterwards.
CURRENT_MODEL = game.Workspace.TestPart
local on = CURRENT_MODEL.Value
local Debounce = false --Create a debounce so a player cant begin the function when its already processing.
script.Parent.ClickDetector.MouseClick:connect(function()
if Debounce == false then --Makes sure the debounce is off before proceeding.
Debounce = true --Sets the debounce on
if on == true then
--Do off stuff
else
--Do on stuff
end
on = not on --This sets it to the opposite value. (true -> false; false -> true)
Debounce = false --Sets the debounce back to off position.
end
end)
Also, please post your code in text format next time instead of screenshots. It makes it much easier to help with.
Thanks for the response back!
I have put it together, thought it mostly works, it doesn’t work all the way
I put the code below (phew) and a video showing what happens, and I know it is connected, because it works the first time, but unfortunately, but does not work after that…
CURRENT_MODEL = game.Workspace.TestPart2
local on = CURRENT_MODEL.Value
local Debounce = false --Create a debounce so a player cant begin the function when its already processing.
script.Parent.ClickDetector.MouseClick:connect(function()
if Debounce == false then --Makes sure the debounce is off before proceeding.
Debounce = true --Sets the debounce on
if on == true then
for i, v in ipairs(CURRENT_MODEL:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
else
for i, v in ipairs(CURRENT_MODEL:GetChildren()) do
v.Transparency = 1
v.CanCollide = true
end
end
on = not on --This sets it to the opposite value. (true -> false; false -> true)
Debounce = false --Sets the debounce back to off position.
end
end)
I have much gratitude towards you!
(and yes I did click it the next time but the video has to be less than 10MB)
Are you getting an error?
If I had to guess, you might be getting an error because an item inside of CURRENT_MODEL doesn’t have the Transparency or CanCollide property.
Try
for i, v in ipairs(CURRENT_MODEL:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency = 1
v.CanCollide = true
end
end
Eureka! It works perfectly, I owe you a great deal! Thanks for spending at least a half-hours work helping me!, I will now probably be clicking that button for the next 3 days(at least.)