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

(Solved) Is there a way to force a player to drop an item through a script?

Asked by 4 years ago
Edited 4 years ago

****I solved this issue myself, no help is needed****

I was making a script that limits the amount of items a player can have in their backpack, and I was going to do this by force dropping whatever item they just picked up if they have the max number of items in their inventory. However, I don't know how to force drop an item that the player just picked up.

My script looks like this:

limit = 2

game.Players.PlayerAdded:Connect(function(p)
    p.Backpack.ChildAdded:Connect(function(tool)
        local items = p.Backpack:GetChildren()
        if #items == limit then
            -- force drop item
        end
    end)
end)

Any help is appreciated!

0
Bro, as soon as I post my answer, you solved it yourself lol Tyler090130 619 — 4y

1 answer

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

You can't necessarily "force" a player to drop an item. You would have to destroy it. Try this out:

limit = 2

game.Players.PlayerAdded:Connect(function(p)
    p.Backpack.ChildAdded:Connect(function(tool)
        local items = p.Backpack:GetChildren()
        if #items > limit then -- greater than 2 (you can also put >= which is greater than or equal to)
            tool:Destroy()
        end
    end)
end)

Backpack

0
Actually, I was able to force-drop it by setting its parent to workspace after waiting .5 seconds. Thank you for the answer, though NoahsRebels 99 — 4y
0
Ah, my mistake then. Tyler090130 619 — 4y
Ad

Answer this question