Hey i’m wondering how to check if a player has a tool i tried this
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
if player.Backpack.Shotgun == nil then
local Gun = game.ReplicatedStorage.Shotgun:Clone()
Gun.Parent = player.Backpack
end
end)
but it didn’t work instead i got Shotgun is not a valid member of Backpack “Players.DevFoll.Backpack”
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
local Tool = player.Backpack:FindFirstChild("Shotgun") or player.Character:FindFirstChild("Shotgun")
if Tool == nil then
local Gun = game.ReplicatedStorage.Shotgun:Clone()
Gun.Parent = player.Backpack
end
end)
for i, v in pairs(Player.Character:GetChildren()) do
if v:IsA("Tool") then
print("player has a tool equipped!")
end
end
for i, v in pairs(Player.Backpack:GetChildren()) do
if v:IsA("Tool") then
print("player has a tool in their backpack!")
end
end
It will check if the Player has a tool, not everyone. It will work if done correctly.
Event.OnServerEvent:Connect(function(Player)
for i, v in pairs(Player.Character:GetChildren()) do -- only checks the players character who fired the server event
if v:IsA("Tool") then
print("player has a tool equipped!")
end
end
for i, v in pairs(Player.Backpack:GetChildren()) do -- only checks the players backpack who fired the server event
if v:IsA("Tool") then
print("player has a tool in their backpack!")
end
end
end)