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

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

Anyone know how this could be done?

1 comment

0

Sorry for the typo

1 answer

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

2 comments

0

What does YOURPART & THING repersent? is it the player

0

In your case, YOURPART would be the seat, whilst THING would be player.Backpack.

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