I am just beginning in Lua and I really need some help on how to remove an item from the StarterPack when a player steps on a brick. Also, the item is called TPTool. My game is filtering enabled and i'm not quite sure what to do.
I'm nowhere near an expert scripter, so please bare in mind with my messy script.
First you should insert a ServerScript into a brick.
01 | local Players = game:GetService( "Players" ) |
02 |
03 | script.Parent.Touched:Connect( function (hit) --when the player touches the part |
04 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) --finds the humanoid through the part that hit the brick, meaning that it finds the parent of the part that touched it and searches for a humanoid |
05 | local player = Players:GetPlayerFromCharacter(humanoid.Parent) --gets the player through the humanoid's parent, which is the character |
06 | local TPTool = player.Backpack:FindFirstChild( "TPTool" ) --searches for the tool inside of the player's backpack |
07 | if TPTool ~ = nil then --basically means if the script finds the tool inside of the backpack |
08 | TPTool:Destroy() --destroys the tool |
09 | end |
10 | end ) |
Might be some errors, but I'm not sure..
Try this script:
01 | local ting = 0 |
02 |
03 | function onTouched(hit) |
04 |
05 | if ting = = 0 then |
06 | ting = 1 |
07 | check = hit.Parent:FindFirstChild( "Humanoid" ) |
08 |
09 | if check ~ = nil then |
10 |
11 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
12 | local tptool = player.StarterGear:findFirstChild( "TPTool" ) |
13 |
14 | if tptool~ = nil then |
15 | player.StarterGear.TPTool:Destroy() |
Accept this answer if it worked:>.