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

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

Asked by 5 years ago

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.

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. TypicallyPacific 61 — 5y
0
Are you talking about a single player's starterpack or multiple? NoLife_David 1 — 5y
0
I just want the gear to be removed, not permanently and make it so if they die, they get the gear back User#23357 0 — 5y
0
Try my script again. CaptainD_veloper 290 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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..

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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:>.

0
indent correctly Vulkarin 581 — 5y
0
It didn't quite work :T User#23357 0 — 5y
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 Vulkarin 581 — 5y
0
It still doesn't seem to work.. User#23357 0 — 5y
View all comments (4 more)
0
Is there any output? Vulkarin 581 — 5y
0
nope ;( User#23357 0 — 5y
0
replace line 12 from `StarterGear` to `Backpack`, remove line 15, change line 16 to just `tptool:Destroy()` Vulkarin 581 — 5y
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 yHasteeD 1819 — 5y

Answer this question