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

How to remove specific item from inventory when player touches an part?

Asked by 6 years ago

this is what i have so far

script.Parent.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then local player = game.Players:FindFirstChild(hit.Parent.Name)

for i=1, 1 do

for i,v in pairs(game.Players:GetPlayers()) do 
for a,b in pairs(v.Character:GetChildren()) do 
        if b:IsA("Tool") or b:IsA("HopperBin") then 
        b:Destroy()

end end end end v.Backpack:ClearAllChildren() end end)

in this script every item gets destroyed so far i knowe. I'm a big noob on coding so I hope someone can help me.

Item that i want to remove from players inventory is called "Blue Master Key"

0
this is for roblox game kexiGamer 21 — 6y
0
And why destroy all the tools after removing a specific one? TheeDeathCaster 2368 — 6y

3 answers

Log in to vote
0
Answered by
zyrun 168
6 years ago
Edited 6 years ago
function onClicked(Plr)
    local Char = Plr.Character
    if Char:FindFirstChild("Blue Master Key", true) then
        Char:FindFirstChild("Blue Master Key", true):Destroy() -- Removes tool from players hands
    end
    if Plr.Backpack:FindFirstChild("Blue Master Key", true) then 
        Plr.Backpack:FindFirstChild("Blue Master Key", true):Destroy() -- Removes tool from players backback
    end
end
0
Character is not a valid member of Script & Stack Begin - Script 'Workspace.Model.Diamond.Part.Teleport', Line 4 - Stack End - Request was throttled. Try sending fewer requests. kexiGamer 21 — 6y
0
i added "script.Parent.ClickDetector.MouseClick:connect(onClicked)" afer last end and it works perfect! Thanx ! Realy aprishiate your help! kexiGamer 21 — 6y
Ad
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago

Hello, kexiGamer!

This script completly removes the key from the player! Removes from player hand and player inventory =D

Hope you like it!

script.Parent.Touched:connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        for i,item in pairs(hit.Parent:GetChildren()) do
            if item.Name == "Blue Master Key" and item:IsA("Tool") then
                item:Destroy()
            end
        end
        for i,item in pairs(game.Players[hit.Parent.Name].Backpack:GetChildren()) do
            if item.Name == "Blue Master Key" and item:IsA("Tool") then
                item:Destroy()
            end
        end
    end
end)

Good luck with your games!

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Hi there and thanx for your answer I get: "Request was throttled. Try sending fewer requests. Key = 551800471 (x4) " and (x4) is just growing and growing. No item dissapears from inventory.

Here is my the script that is working but it is not removing only "BlueMasterKey" tool. It is clearing whole inventory.

function onClicked() 
for i=1, 1 do-----while wait(5) can allso be used and it is working (all other script that i tryed here seems not to work)
for i,v in pairs(game.Players:GetPlayers()) do 
    for a,b in pairs(v.Character:GetChildren()) do 
        if b:IsA("Tool") or b:IsA("HopperBin") then 
            b:Destroy()
        end
    end
    v.Backpack:ClearAllChildren()
end
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Is it possible to start script like this and continue writing so only the "Blue Master Key" gets removed from inventory?

function onClicked()
for i=1, 1 do
-------ADD CODE TO ONLY REMOVE "Blue Master Key" ---->

end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

I realy aprishiate your help and time!

0
`ClearAllChildren` _removes all children from the item_. Just simply remove it to prevent that. TheeDeathCaster 2368 — 6y

Answer this question