Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
0
failed ;-;; IckyInvin5ible7 -70 — 4y
0
Any errors BradNewTypical 232 — 4y
Ad
Log in to vote
-1
Answered by
Lakodex 711 Moderation Voter
4 years ago
Edited 4 years ago

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)
1
This will fail. Ziffixture 6913 — 4y
0
yeah it will BradNewTypical 232 — 4y
0
failed IckyInvin5ible7 -70 — 4y

Answer this question