**First of all, I wanted the door to open when the tool is touched onto the door. But it doesn't work. Maybe I have something that is wrong? Can somebody help me? Thanks!
local door = game.Workspace.Door local plrsbackpack = game.Players.LocalPlayer.Backpack function DoChange() if game.Workspace.Handle.Value == "Staff" and plrsbackpack.AccessCard.Value == "Staff" then game.Workspace.Door.Transparency = 1 game.Workspace.Door.CanCollide = false game.Workspace.Handle.BrickColor = BrickColor.new("Really red") wait(3) game.Workspace.Door.Transparency = 0 game.Workspace.Door.CanCollide = true game.Workspace.Handle.BrickColor = BrickColor.new("Lime green") end end
**If you want to ask me about their parents and stuff, just comment it. Thank you.
I'll make it simple for you... (Yes, it's pretty simple ;P)
"What you are trying to do will simply not wrap up. You want to check the backpack for the access card but want the tool to touch the door? When you equip a tool, it will not be in the backpack anymore, so yeah..."
Let's start again,
local sp = script.Parent local handle = sp.Parent.Handle local cooldown = false function DoChange(hit) print(hit.Parent) if hit.Parent.Name == "Access Card" and hit.Value.Value == "Staff" then cooldown = true sp.Transparency = 1 sp.CanCollide = false handle.BrickColor = BrickColor.new("Really red") wait(3) sp.Transparency = 0 sp.CanCollide = true handle.BrickColor = BrickColor.new("Lime green") end cooldown = false end script.Parent.Touched:connect(DoChange)
First of all, group the door and the handle that you declared. It makes it simpler if you have both in a 'model'.
Now paste this in your script and put the script into the 'door'.
We'll also need to make the tool that will touch the door. I assume that you already know how to. Now name the tool "Access Card". In the tool, insert a part. Name that part "Handle". The handle will be the physical part of your tool. Now make the CanCollide property unchecked. Insert a "StringValue"(from advanced objects) to the Handle. Change the value of the StringValue to "Staff".
Now, to explain the script:
local sp = script.Parent local handle = sp.Parent.Handle local cooldown = false
We declared sp, the door, and the handle, which is the 'handle'. We'll also declare a boolean variable named 'cooldown'. This serves as the cooldown for the function.
The function:
function DoChange(hit) print(hit.Parent) if hit.Parent.Name == "Access Card" and hit.Value.Value == "Staff" then cooldown = true sp.Transparency = 1 sp.CanCollide = false handle.BrickColor = BrickColor.new("Really red") wait(3) sp.Transparency = 0 sp.CanCollide = true handle.BrickColor = BrickColor.new("Lime green") end cooldown = false end script.Parent.Touched:connect(DoChange)
DoChange is the name of the function, hit will be the part that will 'touch' the door. Also, change the handle's BrickColor to "Lime Green". We use print() to check the name of the parent of the touching part. The if statement will check if the parent of the touching part is named "Access Card" and if the value of the string value of the tool's handle is "Staff". If the condition is met, the cooldown will be set to "true", it will apply the changes, then automatically revert it to its original appearance after 3 seconds. After the function has run, it will then set cooldown to "false".
The last part is necessary. It will run the function if the door is touched.
Here is a place I made with the model I worked on, https://www.dropbox.com/s/pc1160ikcjd8nrm/StaffDoorTest.rbxl?dl=0
Try studying it.