Hey! Im trying to make a story game, I need to do check if a player has a tool.
SetRandomPlayerText("Lets Find Something To Patch The Air Leak!")
wait(5)
SetRandomPlayerText("I Found Some Metal Plates!")
workspace.Lava:Destroy()
wait(5)
I want it to be in between wait(5) and SetRandomPlayerText(“I Found Some Metal Plates!”) so you cannot move on into you have the tool, thanks for your assistance!
Because Tool is not in the Character. His script only checks for an equipped Tool named “Tool” in every player. Try renaming it to the tool you want to look for. You may also want to adjust it to check the backpack as well.
''''
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character.Tool or player.Backpack.Tool or player.StarterGear.Tool then
-- stuff
end
end
'''
local function PlayerHasTool(ToolName)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Character:FindFirstChild(ToolName) or v.Backpack:FindFirstChild(ToolName) then
return true;
end
end
return false;
end
Try using this function. Should make things easier if you intend to do this in multiple places in your script.
--This script checks if a player has a TOOL so it can be any tools
for _,v in pairs(game.Players:GetPlayers()) do
if v.Backpack:FindFirstChildWhichIsA("Tool") then
print("There is a tool!")
else
print("No tools found")
end
end
--To make it check a specific tool you just add this:
and v.Backpack:FindFirstChildWhichIsA("Tool").Name == NameOfTool
Just going to quote this and give one possible solution.
local function PlayerHasTool(player, toolName)
local hasTool = false
if player.Backpack:FindFirstChild(toolName) or player.Character:FindFirstChild(toolName) then
hasTool = true
end
return hasTool
end
game.Players.PlayerAdded:Connect(function(player)
wait(3) -- Delay of 3s before checking for the tool
local hasTool = PlayerHasTool(player, "Tool"--[[Change 'Tool' to whatever your tool's name is.]])
if hasTool == true then
print("Player has some tool.")
end
end)
local function searchTool(v)
if v.Backpack:FindFirstChildWhichIsA("Tool") and v.Backpack:FindFirstChildWhichIsA("Tool").Name == NameOfTool then
print("There is a tool!")
else
print("No tools found")
end
end
for _,v in pairs(game.Players:GetPlayers()) do
searchTool(v)
v.Backpack.ChildAdded:Connect(function()
searchTool(v)
end)
end
local function searchTool(v)
if v.Backpack:FindFirstChildWhichIsA("Tool") then
print("There is a tool!")
else
print("No tools found")
end
end
for _,v in pairs(game.Players:GetPlayers()) do
searchTool(v)
v.Backpack.ChildAdded:Connect(function()
searchTool(v)
end)
end
SetRandomPlayerText("Lets Find Something To Patch The Air Leak!")
local function searchTool(v)
if v.Backpack:FindFirstChildWhichIsA("Tool") then
SetRandomPlayerText("Yes! This metal plate will work!")
game.Workspace.Lava:Destroy()
wait(5)
else
print("No tools found")
end
end
for _,v in pairs(game.Players:GetPlayers()) do
searchTool(v)
v.Backpack.ChildAdded:Connect(function()
searchTool(v)
end)
end
SetRandomPlayerText("Good Job!")
It says Good Job! Although I havent pickup the plate, I want it to wait until I pickup the plate.