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

CanCollide on a door does not work when touched with a key?

Okay, so I am making a game, but I have a door that when it is touched with a key a decal will change from a cross to a tick, make the CanCollide on the door turn to false, then switches the decal back to a cross then changing to CanCollide on the door turn to true. It works, but the CanCollide on the door does not change, the transparency on the door is set to 1.

Here is the layout.

Key: http://prntscr.com/9j188p

Door (It is in workspace) : http://prntscr.com/9j18ft

Here is the code (This script is located in the key, as you saw on the screenshot) :

enable = true 
function touch(hit) 
if enable == true then 
enable = false 
if hit:findFirstChild("Door") ~= nil then 
if hit.Door.Value == "KeyCard" and script.Parent.Key.Value == "KeyCard" then
game.Workspace.Gate1.Picture.Decal.Texture = "http://www.roblox.com/asset/?id=336445408"
game.Workspace.door.CanCollide = false
wait(2)
game.Workspace.Gate1.Picture.Decal.Texture = "http://www.roblox.com/asset/?id=336442458"
game.Workspace.door.CanCollide = true
end 
end 
end 
enable = true 
end 
script.Parent.Handle.Touched:connect(touch)

3 comments

0

How many instances with the name "door" are in the workspace? Could you maybe put a link to a screenshot of the entire workspace?

0

Wait, why put a script in a key? What if you want more than one key? You will have multiple scripts when you only need one.

2 answers

✓ Accepted answer

Your problem is actually quite simple. On line 5, it tries to find a child named "Door", when in the picture you showed us, the Door object is spelled with a lowercase D.

So line 5 should be this:

if hit:findFirstChild("door") ~= nil then

2 comments

0

Still no :c

1

I got a new one and it works. c:

Try this:

local Debounce = false
local Door = ?
local OpenTime = 5
local KeyName = "Key"
local Decal = script.Parent.Decal or Instance.new("Decal",script.Parent)
local DecalCrossId = 0
local DecalTickId = 0

Decal.Texture = ("http://www.roblox.com/asset/?id="..DecalCrossId)

Door.Touched:connect(function(Part)
if Part.Name = KeyName and Debounce = false then
Debounce = true
Door.CanCollide = false
Decal.Texture = ("http://www.roblox.com/asset/?id="..DecalTickId)
wait(OpenTime)
Door.CanCollide = true
Decal.Texture = ("http://www.roblox.com/asset/?id="..DecalCrossId)
Debounce = false
end

1 comment

0

Didn't work at all, unfortunately :c

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