Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I have a problem with a door script that goes in clickdetector, how to fix this?

Asked by 5 years ago
Edited 5 years ago

I am a beginner scripter and I am trying to make a simple open and close door that changes the transparency and cancollide when clicked and changes it back to default when clicked again. I need help on this script

game.Workspace.Part.CanCollide(function(close) close = true end)

local clickdetector = game.Workspace.Part.ClickDetector clickdetector.MouseClick:Connect(function() game.Workspace.Part.Transparency = (0.5) game.Workspace.Part.CanCollide = false close = false end) if close(false) then clickdetector.MouseClick:Connect(function() game.Workspace.Part.Transparency = (0) game.Workspace.Part.CanCollide = true end) end

the scripts error: 20:39:08.891 - Workspace.Part.ClickDetector.Script:1: attempt to call field 'CanCollide' (a boolean value)

if anyone could help me that would be great.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Try this in the script

local clickDetector = script.Parent.ClickDetector
clickDetector.MouseClick:Connect(function()
    if script.Parent.Transparency == 0 then
        script.Parent.Transparency = .5
        script.Parent.CanCollide = false
    else
        script.Parent.Transparency = 0
        script.Parent.CanCollide = true
    end
end)

What this does is... When you click the door it will check to see if it is open, if it is then it will close it. If it isn't then it will open it

Ad

Answer this question