i've been trying to make a click button door but every time I do it, it wont work but it shows no errors. what I want it to do is when you click the door the door cancollie = true and the image transparency = 1. and when you click it again the door cancollide = false and the image transparency = 0. this is te script:
function OnClicked (mousebutton1) script.parent.image.transparency = 1 script.parent.CanCollide = true
if script.parent.ClickDetector == true then script.parent.image.transpatency = 0 script.parent.CanCollide = false end
end
Here's a really simple working script make sure you set it up like this
Put script inside of block
Add a click detector inside of block
Add a boolvalue with the name "Value" inside of block
Script:
B = script.Parent.Value.Value -- checks for the value of value lol function CanCollide() if B == true then B = false --When it's false it is like this (default cancollide and not transparent) script.Parent.Transparency = 0 script.Parent.CanCollide = true else B = true -- after clicking (for first time) script.Parent.Transparency = 1 -- change to whatever you want script.Parent.CanCollide = false end end script.Parent.ClickDetector.MouseClick:connect(CanCollide) -- make sure this is correct (ClickDetector) --
If you need any help let me know! Make sure that you accept my answer if it works :)
First of all, if you don't already have one, create a ClickDetector
inside of your button part. A ClickDetector is a Roblox instance that you put in a part, and it waits for a player to click that part. You also need to call it inside of your script
local clicker = part.ClickDetector --assuming part is defined
Secondly, you need to call your function, as wfvj014 stated. You can do that with the MouseClick
event like so
local door = script.Parent local ImageTransparency = script.Parent.image.Transparency local clicker = part.ClickDetector --assuming part is defined function onClicked(mousebutton1) if ImageTransparency == 1 then ImageTransparency = 0 door.CanCollide = true end if ImageTransparency == 0 then ImageTransparency = 1 door.CanCollide = false end end clicker.MouseClick:connect(onClicked)
Another thing I noticed is that you have an unused mousebutton1 parameter for your function. I don't know if you will use it later, so I left it there.
Hope this fixes your problem --connor12260311
Try this
local door = script.Parent local ImageTransparency = script.Parent.image.Transparency function onClicked(mousebutton1) if ImageTransparency == 1 then ImageTransparency = 0 door.CanCollide = true end if ImageTransparency == 0 then ImageTransparency = 1 door.CanCollide = false end end
Tell me if you get any errors Accept this answer if it worked leave a comment if it didn't. :D