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

Why doesn't the remove feature doesn't remove the tool out of the users inventory when clicked on?

local Clickdetector = script.Parent:WaitForChild("ClickDetector")

local ToolNames = {"Milk"}

function playerAdded (player)

if player.Name == "Player" then

wait(2)

Clickdetector.MouseClick:Connect(function(Player)

if Player and Player.Character then

if ToolNames then

game.Players.player.Backpack.Milk:remove ()

end

end

end)

end

end

1 answer

  local ToolNames = {"Milk"}

  

function Clicked(Player)

if Player and Player.Character and ToolNames then

for i,z in pairs(game:GetService("Players"):GetPlayers()) do

for i,v in pairs(ToolNames) do

z.Character.Humanoid:UnequipTools()

z.Backpack:FindFirstChild(v):Destroy()

end

end

end

end

  

  

script.Parent.ClickDetector.MouseClick:connect(Clicked)

The script receives if the player touched. If he touched then the script will get every player by using for I,z in pairs with players, then will take every toolnames by doing for I,v in pairs. After the script will unequip the tools and remove 1 tool with the name of Milk.

20 comments

0

This script works but it destroys everything in my inventory (which I only want it to destroy one) and it is player specific (want it to be non-player specific)

0

So you want it to destroy only one for everyone?

0

There we go! Updated the script.

0

It doesn't even remove anything out of my inventory :(

0

You need something called "Milk"

0

I have the "Milk" in the server storage and

0

you need it in your inventory

0

I do but it the script doesnt remove it

0

Error? Where did you put the script?

0

inside a guy's arm, the "milk" is a tool and im trying to remove the milk from the player as if they are giving the milk.

0

is there an error because it works for me, if it really doesnt work ill make a model

0

k thank you

0

Did you change the playername to yours?

0

Wait now try the script i updated it

0

k

0

Thanks it works now. Im new to this site, do you know how to verify answers.

0

Its right under here, if you are using chrome it wont work. So use edge for now just to accept my answer :)

0

-1. No explanation was given.

0

Here I explained! If you could remove the -1 it would be really appreciated because I took alot of time to do this and talking with him. I tried my best at explaining :)

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