Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can I get help with a toggling clickdetector button script? (No Errors in Output)

So I have a script where when you click it changes a bool value and is supposed to change whether something is visible or not yet it isn't working I tried both else if and elseif --code end but both aren't working, any help?

Discord: Unknown Intelligence#6569

local bool = false
script.Parent.ClickDetector.MouseClick:Connect(function()
    local shield = script.Parent.Parent.Part
    if bool == false then
    shield.Transparency = 1
    shield.Transparency = false
    bool = true
    else if bool == true then
    shield.Transparency = 0
    shield.CanCollide = true
    bool = false
end
end
end)

Using elseif:

local bool = false
script.Parent.ClickDetector.MouseClick:Connect(function()
    local shield = script.Parent.Parent.Part
    if bool == false then
    shield.Transparency = 1
    shield.Transparency = false
    bool = true
    elseif bool == true then
    shield.Transparency = 0
    shield.CanCollide = true
    bool = false
end
end)

1 answer

✓ Accepted answer

Yeah it works. Well kinda...

You set shield.Transparency = 1 and then shield.Transparency = false.

Transparency is a number value that only accepts numbers 1 >= x >= 0 (between 1 and zero)

local bool = false
script.Parent.ClickDetector.MouseClick:Connect(function()
    local shield = script.Parent.Parent.Part
    if bool == false then
    shield.Transparency = 1
    --shield.Transparency = false -- this is what messed up your code. Everything else works fine. 
	-- I assume you meant to put CanCollide = false so here you go
	shield.CanCollide = false
    bool = true
    elseif bool == true then -- also yea I would just use ifelse 
    shield.Transparency = 0
    shield.CanCollide = true
    bool = false
end
end)

1 comment

0

Thank ya m8y

This discussion is preserved as it was. New answers, comments, and votes are closed.