Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how? to turn this code into a part.touched code

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

2 answers

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.

local ToolName = game.ServerStorage.Keycard.Name
local door = script.parent

door.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	        if Player.Backpack:FindFirstChild(ToolName) then 
	            print("Player has tool in backpack!") 
	        else 
	            print("Player does not have tool in backpack!")
	        end
	end
end)

2 comments

0

failed ;-;;

0

Any errors

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

local ToolName = game.ServerStorage.Keycard.Name
local door = script.parent
		 
door.Touched:Connect(function(Player)
	if Player.Backpack:FindFirstChild(ToolName) then 
		print("Player has tool in backpack!") 
	else 
		print("Player does not have tool in backpack!")
	end
end)

3 comments

1

This will fail.

0

yeah it will

0

failed

This discussion is preserved as it was. New answers, comments, and votes are closed.