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

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

Asked by
awfulszn 394 Moderation Voter
9 years ago

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)
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? Wutras 294 — 9y
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. Vezious 310 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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
0
Still no :c awfulszn 394 — 9y
1
I got a new one and it works. c: awfulszn 394 — 9y
Ad
Log in to vote
0
Answered by
Vezious 310 Moderation Voter
9 years ago

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
0
Didn't work at all, unfortunately :c awfulszn 394 — 9y

Answer this question