Equip Item script not working

I have been stumped on writing this code for a while, i’m a newbie coder and I only know the basics. I’m trying to make an Item equip script when the item on the ground is clicked. The item in question is a pair of pliers.

So far I have tried taking the tool from the workspace and duping it into starterPack but this doesn’t seem to work

Here is my script:
local clickdetector = workspace.Pliers.ClickDetector

local pliers = workspace.Pliers

clickdetector.MouseClick:Connect(function()

local model = workspace.Pliers:Clone()

model.Parent = game.StarterGui --I dont know what to replace this with

pliers:Destroy()

end)

You would need to put it in the Player.Backpack, not starter pack. Starter pack is the set of tool that the player starts with, and since you want the player to pick up the tool immediately you would add it to their Player.Backpack.

You could modify your code like so:

local clickdetector = workspace.Pliers.ClickDetector
local pliers = workspace.Pliers

clickdetector.MouseClick:Connect(function(player) -- note that click detectors tell you which player clicked on them
    local model = workspace.Pliers:Clone()
    model.Parent =  player.Backpack -- this is where it should go
    pliers:Destroy()
end)

Useful Links:


Note, in the future when pasting code, surround them with ``` backticks so it looks formatted, like so:
```
– code
```
Which ends up looking like:

 -- code
1 Like

Put it in the character instead if you want them to equip it, or their backpack if you just want them to have the item. For example:

local clickdetector = workspace.Pliers.ClickDetector

local pliers = workspace.Pliers

clickdetector.MouseClick:Connect(function(player) -- the player who clicked is the first parameter of clickdetector's MosueClick
	local model = workspace.Pliers:Clone()
	model.Parent = player.Character -- equip the tool directly 
	pliers:Destroy()
end)
3 Likes

local pliers = workspace.Pliers

clickdetector.MouseClick:Connect(function(plr)

pliers.Parent = plr.Backpack

end)

Hello. Tools have to be parented to the player’s backpack so they can later equip them with Roblox’s built-in inventory system. StarterGui is used to store gui objects, while StarterPack is where you generally place tools to be in player’s inventory upon start of the game and after respawning.

Now you need to know who clicked the tool, right? That’s where playerWhoClicked argument comes. Pay attention to your script with these two modifications:

local clickdetector = workspace.Pliers.ClickDetector

local pliers = workspace.Pliers

clickdetector.MouseClick:Connect(function(Player) -- Note the "Player" thing here, Roblox will assign to this variable the player instance

    local model = workspace.Pliers:Clone()

    model.Parent = Player.Backpack -- that's where the tool should go to!

    pliers:Destroy()

end)

Hope this helped, if you didn’t understand something just ask!

1 Like

Hey!

You may want to check this out, a post made by me, and use the key tutorial to pick it up?
It helps make a more efficient version of what you want to do.

Anyway, try this, insert a local script inside of starter player scripts;

 game.Workspace.Pliers.ClickDetector.MouseClick:Connect(function(playerClicked)
 game.Workspace.Pliers:Destroy()
 game.ReplicatedStorage.Pliers.Parent = playerClicked.Backpack
end)

Hope I helped

You haven’t located the ClickDetector, so this won’t work.

Oh yea I forgot to copy that line lol

I have tried every one of the current responses with the script in StarterPlayerScripts
but so far none of the responses have caused the pliers to enter my inventory and get deleted. Some of the scripts delete the item but the item never enters the inventory.

This script worked the best but every time I clicked it in my inventory it would do the thing where your character gets teleported to wherever the pliers were, even if I un-anchor the pliers

Check if the pliers are welded to anything, because that would cause the bug you described.

Make sure they aren’t welded to the chair or anything.

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