Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I check if a player has a tool in their backpack?

Hello. I have the following script

local gui = script.Gui
local gui2 = script.Gui2
local domClickedEvent = game.ReplicatedStorage.Events.DominusClicked
local Tool = game.Players.LocalPlayer.Backpack:FindFirstChild("Dynamite")
domClickedEvent.OnClientEvent:Connect(function()

	if Tool then 
	
		print("its good")
		gui2.Enabled = true
		game.Players.LocalPlayer.Backpack.Dynamite:Destroy()
		wait(8)
		game.Workspace.Boulders:Destroy()
		
		
		
	else
	
	gui.Enabled = true


game.Players.LocalPlayer.PlayerGui.Dominus.NextClicked.Enabled = true
end
end)

Basically this should happen - the script should check if the player has the tool named "Dynamite". If the player does then it makes gui2 appear, if not then gui should appear. gui keeps on appearing everytime, even though the player has Dynamite in their backpack. The Dynamite is not held when this is done, and this is a localscript located in startergui.

This is the script that triggers the event if it helps.

local clickDetector = script.Parent
local domClickedEvent = game.ReplicatedStorage.Events.DominusClicked
local debounce = false

clickDetector.MouseClick:Connect(function(player)
	if not debounce then
		debounce = true
		domClickedEvent:FireClient(player)
		print(player.Name.. "has clicked the brick")
		wait(1)
		debounce = false
		
		


	end
end)

I do not know why the script is unable to detect the tool, any help would be appreciated.

Thank you.

2 comments

0

Hey, I would like to help you, but I can't read your script. Can you please show ALL of your script in code lines?

0

Sorry, all done.

1 answer

✓ Accepted answer

Ok, so I think your problem is that you are using "LocalPlayer" in a server script. I can't really get a good view of your problem, so can you edit your question to also have the client script? I will be able to extend this answer and help you more if I see the localscript aswell.

7 comments

0

Sorry, i'm a bit confused. By client script, do you mean the one that triggers the remote event? Also i'm pretty sure i'm using a local script.

0

Yes. The one that triggers the event is the one that is the localscript right? and the server script is the one you posted?

0

The one I posted is the local script. It's located inside starergui.

0

ok wait

0

I added the script to the post, perhaps it will help you better understand. Sorry if i'm confusing you.

0

so you mean that the script that checks for the tool is a serverscript and the one that fires the event is the localscript>?

0

The script that checks for the tool is a local script located in startergui, so the player. The 2nd script, the one that fires the event, is a serverscript located in workspace.

This discussion is preserved as it was. New answers, comments, and votes are closed.