I'm at a very beginner level of coding and basically want to implement a system where there are 4 keys to open 4 locks before allowing you to pass through a door. So that every player has to find all of the keys, I want a system where the lock will only be opened by an individual player.
Here is my current script:
GoldenLock (the door/lock that will disappear)
local COOLDOWN_TIME = 1
local cooldown = false
script.Parent.Touched:connect(function(p)
if p.Parent.Name == "Golden Key" then
if cooldown then
return
end
cooldown = true
script.Parent.Transparency = 0.5
script.Parent.CanCollide = false
wait(3)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
wait(COOLDOWN_TIME)
cooldown = false
end
end)
I have tried tinkering with the script and placing it in StarterCharacterScripts, but it still opens for all clients when the key part touches the door:
local door = game.Workspace.GoldenLock
local COOLDOWN_TIME = 1
local cooldown = false
door.Touched:connect(function(p)
if p.Parent.Name == "Golden Key" then
if cooldown then
return
end
cooldown = true
door.Transparency = 0.5
door.CanCollide = false
wait(3)
door.Transparency = 0
door.CanCollide = true
wait(COOLDOWN_TIME)
cooldown = false
end
end)
I tried adding local to line 5, but either am doing it wrong or simply don't understand the issue. I only learned how to script about a week ago, and would appreciate any help somebody could give.

3 comments
This is a LocalScript correct?
@Omenoire (off topic) you joined Roblox in 2008, which is pretty cool.
@Benbebop Yes it is a localscript inside of StarterCharacterScripts