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

how to make a script where when a player sits all their tools from backpack gets destoryed?

Asked by 6 years ago

Anyone know how this could be done?

0
Sorry for the typo lopehole12 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Seats (and all Instances for that matter) have an event by the name of ChildAdded. It's accessed by a line such as YOURPART.ChildAdded:connect(function(child).

The variable 'child' will give you the child added. You can use an if statement to check the name of the child, which will allow you to find the player.

local player = nil
YOURPART.ChildAdded:connect(function(child)
    if child.Name == "SeatWeld" then
        player = game.Players:GetPlayerFromCharacter(YOURPART.Occupant.Parent)
    end
end)

As for the backpack, this is accessed within each player by using PLAYER.Backpack. There is a function called :GetChildren(), which will allow you to do what you require.

For loops reiterate over each value in an array.

for i,v in pairs(THING:GetChildren()) do

end

This is a for loop. The variable 'v' signifies an object, which could then be destroyed with v:Destroy().

Hope this helped.

Thanks,

Explosion

0
What does YOURPART & THING repersent? is it the player lopehole12 0 — 6y
0
In your case, YOURPART would be the seat, whilst THING would be player.Backpack. ZeExplosion 210 — 6y
Ad

Answer this question