How to detect if a tool is in the Player's Inventory

  1. What do you want to achieve? Basically, I want the server script to detect if I picked up a specific tool.

  2. What is the issue? I can’t find a way to do so that works with the current script.

  3. What solutions have you tried so far? I’ve already tried using :FindFirstChild, but it only works on LocalScripts. I also tried getting the character of the player and detecting if the tool is in the inventory but all I got were errors.

Script:

local DialogueEvent = game.ReplicatedStorage.RemoteEvents:FindFirstChild("DialogueEvent")
local ObjectiveEvent = game.ReplicatedStorage.RemoteEvents:FindFirstChild("ObjectiveEvent")

local ToggleDialogueEvent = game.ReplicatedStorage.RemoteEvents:FindFirstChild("ToggleDialogueEvent")
local ToggleObjectiveEvent = game.ReplicatedStorage.RemoteEvents:FindFirstChild("ToggleObjectiveEvent")

local function MainGame()
	ToggleDialogueEvent:FireAllClients(true)
	DialogueEvent:FireAllClients("Agent: Remember what you're here for.")
	wait(3.1)
	DialogueEvent:FireAllClients("Agent: Here are you're objectives.")
	wait(2)
	ToggleDialogueEvent:FireAllClients(false)
	ToggleObjectiveEvent:FireAllClients(true)
	ObjectiveEvent:FireAllClients("Investigate The Crash Site")
	
	for i = 1, 0, -0.05 do
		game.Workspace.Mark.Transparency = i
		wait(0.01)
	end
	
	repeat wait() until game.Workspace.Triggers.DialogueTriggers:FindFirstChild("WhisperTrigger") == nil
	
	game.Workspace.Mark.Transparency = 1
	game.ReplicatedStorage.VoiceOvers.Whispers.Playing = true
	wait(1)
	game.ReplicatedStorage.Breathing.Playing = true
	
	wait(4)
	ToggleDialogueEvent:FireAllClients(true)
	game.ReplicatedStorage.VoiceOvers:WaitForChild("VoiceOver2").Playing = true
	DialogueEvent:FireAllClients("Agent: Is everything alright?")
	wait(2.6)
	ToggleDialogueEvent:FireAllClients(false)
	game.Workspace.Phone.Handle.ProximityPrompt.Enabled = true
end

wait(4)
MainGame()

Any help will be appreciated!

im not sure but maybe use .ChildAdded?
like this?

for i,v in ipairs(game.Players:GetPlayers()) do
	v.Backpack.ChildAdded:Connect(function(child)
		if child.Name == "Insert your name here" then
			--code
		end
	end)
end
3 Likes

You can use FindFirstChild in server scripts too, for example

for _,v in ipairs(game.Players:GetPlayers()) do
	if v.Backpack:FindFirstChild("Tool Name") then
		--your code
	end
end

or

--plr - Player Object (in game.Players)
if plr.Backpack:FindFirstChild("Tool Name") then
	--your code
end
2 Likes

Thank you so much! I’ve embarassingly been trying to find a solution for this for like 6 hours. Thank you very much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.