Hello! I have a door that opens by the access of a key card. I have the card laying next to the door for a player to be able to choose their preferred room and pick up their card accordingly.
I am wondering how I can make it so that players can only pick up one card and say something like "you already own a card!" when they try to pick up another door's card. (It doesn't NEED to say anything - the function just needs to work that they can't pick up another card)
The reason I do not just put these in the starter pack is because they need to be able to pick their own door, not randomly assign it. In order for the card to work, it is specific in which door it works with. (ex. Card1 works with Door1, not Door2)
I also would like to put down 2 cards for each door as they are meant to be shared rooms. I think this should be an easy part but I wanted to specify just in case this clashes with something.
The card also needs to be regenerated upon a player leaving a server for a new player to be able to pick up, and not losing the card upon death once picked up. But they can't spawn in with the same card the next time they play the game.
So I am looking for if it is possible and what the script would be to not allow players to pick up more than one card (tool) and how to regen it after the player leaves the server?
I would appreciate your help so much. If you need any further details to understand please just ask. Thank you so much!!!
This also may help:
Player selects a card. The card is moved to the player's StarterGear, which is like a per-player version of StarterPack. If that player dies they won't lose it.
Make a script in every card that checks if the player clicking on it already has a card. You need to check two places - the backpack, and the character (which is where tools go when you're holding them). Deny them if it finds a card in either of those two places.
Regenerating the card is the hardest part. There's an event called PlayerRemoving that tells you when a player is leaving and lets you do whatever you want before then, but if the player loses connection that isn't guaranteed to fire off properly. The best way to do it would be to keep track of the player who owns the card using another script and regenerate it if the player no longer exists.
Door's script (I am sorry I do not know how to properly paste a script) :( :
print("Advanced SpecialDoor Script loaded")
permission = { "Card1" }
Door = script.Parent.Parent.PersonDoor
DoorMesh = script.Parent.Parent.PersonDoor.Mesh
Sensor = script.Parent
function checkOkToLetIn(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end
function onTouched(hit)
print("Sensor Hit")
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil ) then
--
print("Human touched door")
if (checkOkToLetIn(human.Parent.Name)) then
print("Human passed test")
Wait(0.001)
script.Parent.Parent.Dot1.Transparency = 0
script.Parent.Parent.Beep:Play()
wait(0.4)
script.Parent.Parent.Dot2.Transparency = 0
script.Parent.Parent.Beep:Play()
wait(0.4)
script.Parent.Parent.Dot3.Transparency = 0
script.Parent.Parent.Beep:Play()
wait(0.4)
script.Parent.Parent.Open.Transparency = 0
script.Parent.Parent.Close.Transparency = 1
script.Parent.Parent.Beep2:Play()
wait(0.2)
script.Parent.Parent.OpenSound1:Play()
wait(0.1)
script.Parent.Parent.OpenSound2:Play()
script.Parent.Parent.HandlePart3.Transparency = 0
script.Parent.Parent.HandlePart4.Transparency = 0
script.Parent.Parent.HandlePart.Transparency = 1
script.Parent.Parent.HandlePart2.Transparency = 1
script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.9, 0.5, 1.01)
Door.Transparency = 0
wait(0.02)
Door.CanCollide = false
script.Parent.Parent.Dot1.Transparency = 1
script.Parent.Parent.Dot2.Transparency = 1
script.Parent.Parent.Dot3.Transparency = 1
wait(3)
script.Parent.Parent.Open.Transparency = 1
script.Parent.Parent.Close.Transparency = 0
script.Parent.Parent.HandlePart3.Transparency = 1
script.Parent.Parent.HandlePart4.Transparency = 1
script.Parent.Parent.HandlePart.Transparency = 0
script.Parent.Parent.HandlePart2.Transparency = 0
script.Parent.Parent.OpenSound2:Play()
wait(0.1)
script.Parent.Parent.OpenSound1:Play()
script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.01, 0.01, 0.01)
Door.CanCollide = true
Door.Transparency = 0
end
end
end
connection = Sensor.Touched:connect(onTouched)

2 comments
This is possible but how are you giving the tool to the player, is this using a click detector? If you have any code pls include it.
Thank you for your response! It is of touch interest, but we can switch it to click if that is how it will work. Above I edited the original post to include the door script - I'm sorry I don't know how to properly post the script (I tried messing with the buttons I am new :( ). Thank you so much for your help I appreciate it so much!