Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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.

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? RetroGalacticGamer 331 — 4y
0
Sorry, all done. Alexanders1123 16 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

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. Alexanders1123 16 — 4y
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? RetroGalacticGamer 331 — 4y
0
The one I posted is the local script. It's located inside starergui. Alexanders1123 16 — 4y
0
ok wait RetroGalacticGamer 331 — 4y
View all comments (3 more)
0
I added the script to the post, perhaps it will help you better understand. Sorry if i'm confusing you. Alexanders1123 16 — 4y
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>? RetroGalacticGamer 331 — 4y
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. Alexanders1123 16 — 4y
Ad

Answer this question