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

How do I clear a players backpack when the player touched a part?

Asked by
1itxd 7
4 years ago

I'm trying to make a game where players can battle in this classic place but there are also some minigames for players to play. When players enter the minigames, how do I clear their backpack?

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
4 years ago

I will assume that you know very little Lua, or Roblox Lua to be more precise.

To start off, you need to have something that the player will touch, likely a part. Position the part at the entrance, so that you know the player will touch it, and place a Script (Server Script) as a child in that part with the following code:

local detection = script.Parent -- A part that the player touches
detection.Touched:Connect(function(otherPart)
    for _,v in pairs(game:GetService("Players"):GetChildren()) do
        if otherPart:IsDescendantOf(v.Character) then
            v.Backpack:ClearAllChildren()
        end
    end
end)

Cheers. Accept this if it helped you.

0
Thank you so much! I've been having a lot of trouble with how to do this. Cheers! 1itxd 7 — 4y
0
Accept his answer please Noonekirby 162 — 4y
Ad

Answer this question