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)
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
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