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.
How do you remove an item from a player's Starterpack when they step on a brick?
2 answers
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.
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit) --when the player touches the part
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
local player = Players:GetPlayerFromCharacter(humanoid.Parent) --gets the player through the humanoid's parent, which is the character
local TPTool = player.Backpack:FindFirstChild("TPTool") --searches for the tool inside of the player's backpack
if TPTool ~= nil then --basically means if the script finds the tool inside of the backpack
TPTool:Destroy() --destroys the tool
end
end)
Might be some errors, but I'm not sure..
Try this script:
local ting = 0
function onTouched(hit)
if ting == 0 then
ting = 1
check = hit.Parent:FindFirstChild("Humanoid")
if check ~= nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local tptool= player.StarterGear:findFirstChild("TPTool")
if tptool~= nil then
player.StarterGear.TPTool:Destroy()
player.Backpack.TPTool:Destroy()
end
end
ting = 0
end
end
script.Parent.Touched:connect(onTouched)
Accept this answer if it worked:>.
8 comments
indent correctly
It didn't quite work :T
^You need to change "leaderstats" on line 12 to whatever the actual tool name is, I'm not sure why it's named that to begin with
It still doesn't seem to work..
Is there any output?
nope ;(
replace line 12 from StarterGear to Backpack, remove line 15, change line 16 to just tptool:Destroy()
You need to explain the script. and :connect and :findFirstChild is deprecated. use: :Connect and :FindFirstChild, also you can use if check then and if tptool then dont need to use if check ~= nil then and if tptool ~= nil then
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
So would you want it so it removes from the starterpack service or from their backpack as if you remove it from starterpack service, when someone joins the game they won't be able to get that item.
Are you talking about a single player's starterpack or multiple?
I just want the gear to be removed, not permanently and make it so if they die, they get the gear back
Try my script again.