Hello, i was wondering if it would be possible to check the players backpack in a one player server as shown in image:
The scenario is in a if loop where only if the player contains a specific item in their backpack then the script does something like open a door or move a part. I would like to do this with a proximity prompt in a script.
How would i edit this script to make it detect for a specific item in the players inventory and then if they have it, it will preform the function?
If you had a script, it would be very useful if you published it, also, if it is to all players
local Target = "Sword" -- name of the object to search
function Check(Player:Player)
if Player:FindFirstChild("Backpack") and Player.Backpack:FindFirstChild(Target) then
-- Code
end
end
for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
Check(Player)
end
if it’s only one
local Target = "Sword" -- name of the object to search
local Player = -- player in question
if Player:FindFirstChild("Backpack") and Player.Backpack:FindFirstChild(Target) then
-- Code
end
This code wont work for some reason.
Why?
What do i need to fix?
local Target = “Sword” – name of the object to search
local Player = game.Players.PlayerAdded:Connect(function(player) – player in question (might delete this later)
local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
ProximityPrompt.Triggered:Connect(function()
if Player:FindFirstChild(“Backpack”) and Player.Backpack:FindFirstChild(Target) then
– Code
if ProximityPrompt.ActionText == “Open” then
Door.Transparency = .5
Door.CanCollide = false
ProximityPrompt.ActionText = “Close”
else
Door.Transparency = 0
Door.CanCollide = true
ProximityPrompt.ActionText = “Open”
end
end
end)
local Target = “Sword” – name of the object to search
local Player = game.Players.PlayerAdded:Connect(function(player) – player in question (might delete this later)
local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
ProximityPrompt.Triggered:Connect(function()
if Player:FindFirstChild(“Backpack”) and Player.Backpack:FindFirstChild(Target) then
– Code
if ProximityPrompt.ActionText == “Open” then
Door.Transparency = .5
Door.CanCollide = false
ProximityPrompt.ActionText = “Close”
else
Door.Transparency = 0
Door.CanCollide = true
ProximityPrompt.ActionText = “Open”
end
end
local Target = "Sword" -- name of the object to search
local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
ProximityPrompt.Triggered:Connect(function(Player)
if Player:FindFirstChild("Backpack") and Player.Backpack:FindFirstChild(Target) then
-- Code
if ProximityPrompt.ActionText == "Open" then
Door.Transparency = .5
Door.CanCollide = false
ProximityPrompt.ActionText = "Close"
else
Door.Transparency = 0
Door.CanCollide = true
ProximityPrompt.ActionText = "Open"
end
end
end)
local Target = "Sword" -- name of the object to search
local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
ProximityPrompt.Triggered:Connect(function(Player)
if Player:FindFirstChild("Backpack") and Player.Backpack:FindFirstChild(Target) then
-- Code
if ProximityPrompt.ActionText == "Open" then
Door.Transparency = .5
Door.CanCollide = false
ProximityPrompt.ActionText = "Close"
else
Door.Transparency = 0
Door.CanCollide = true
ProximityPrompt.ActionText = "Open"
end
end
end)
game.Players.PlayerAdded:Connect(function(player)--player is now able to be used in event code
local Target = “Sword” – name of the object to search
local Player = game.Players.PlayerAdded:Connect(function(player) – player in question (might delete this later)
local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
ProximityPrompt.Triggered:Connect(function()
if Player:FindFirstChild(“Backpack”) and Player.Backpack:FindFirstChild(Target) then
– Code
if ProximityPrompt.ActionText == “Open” then
Door.Transparency = .5
Door.CanCollide = false
ProximityPrompt.ActionText = “Close”
else
Door.Transparency = 0
Door.CanCollide = true
ProximityPrompt.ActionText = “Open”
end
end
end)
end)