local ToolName = workspace.Keycard door = script.parent
game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) if Player.Backpack:FindFirstChild(ToolName) then print("Player has tool in backpack!") else print("Player does not have tool in backpack!") end end)
end)
it works but how do i make it work if the player touches the door
Don't use the guys above me, his has some problems.
Edit: Don't worry about the tabs. The site has some problems with the formation of code.
01 | local ToolName = game.ServerStorage.Keycard.Name |
02 | local door = script.parent |
03 |
04 | door.Touched:Connect( function (hit) |
05 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
06 | local Player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | if Player.Backpack:FindFirstChild(ToolName) then |
08 | print ( "Player has tool in backpack!" ) |
09 | else |
10 | print ( "Player does not have tool in backpack!" ) |
11 | end |
12 | end |
13 | end ) |
Next time please use the code boxes please. Thank you! Paste this in to your door part.
Some security stuff
Put the Keycard in serverstorage so it cannot be hacked / stolen
01 | local ToolName = game.ServerStorage.Keycard.Name |
02 | local door = script.parent |
03 |
04 | door.Touched:Connect( function (Player) |
05 | if Player.Backpack:FindFirstChild(ToolName) then |
06 | print ( "Player has tool in backpack!" ) |
07 | else |
08 | print ( "Player does not have tool in backpack!" ) |
09 | end |
10 | end ) |