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

Removing a tool from Backpack and StarterGear?

Asked by 10 years ago

Okay so in a previous question I learned about StarterGear.

So now I need to remove a Tool from 3 places

  • The player's character
  • The player's backpack (if not equipped)
  • the players StarterGear (so they don't respawn with it)

I made this script, And I deletes it from the startergear, but nowhere else.

Here's the script

local buttonPressed = false


script.Parent.Touched:connect(function(hit)
    if not buttonPressed then


        buttonPressed = true
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

        local character = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        local Bucket = player.Backpack.Branch
        local SG = player.StarterGear
        local equip = character.Branch

        Bucket:Destroy()
        equip:Destroy()
        SG.Branch:Destroy()



    end

    wait(10)
    buttonPressed = false

    end
    end)

1 answer

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
10 years ago

In this script, you are not sure if the player actually has the items. Therefore, you should do a findFirstChildand check if each one is there. Check this out:

local buttonPressed = false


script.Parent.Touched:connect(function(hit)
    if not buttonPressed then


        buttonPressed = true
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

        local character = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        local Bucket = player.Backpack:findFirstChild("Branch")
        local SG = player.StarterGear:findFirstChild("Branch")
        local equip = character:findFirstChild("Branch")

        if Bucket then
                Bucket:Destroy()
        end
        if equip then
                equip:Destroy()
        end
        if SG then
                SG:Destroy()
        end



    end

    wait(10)
    buttonPressed = false

    end
    end)
0
So this worked better than my last script, its just even though after i touched it and it dissapears, It's not in any of the player's things, yet when I reset I get it back. That's weird SpazzMan502 133 — 10y
Ad

Answer this question