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

How do you remove an item from a player's Starterpack when they step on a brick?

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.

4 comments

0

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.

0

Are you talking about a single player's starterpack or multiple?

0

I just want the gear to be removed, not permanently and make it so if they die, they get the gear back

0

Try my script again.

2 answers

✓ Accepted answer

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

0

indent correctly

0

It didn't quite work :T

0

^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

0

It still doesn't seem to work..

0

Is there any output?

0

nope ;(

0

replace line 12 from StarterGear to Backpack, remove line 15, change line 16 to just tptool:Destroy()

0

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.