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

How to make this script remove all tools from backpack when you teleport?




local part = workspace.Cabin
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local LowerTorso = plr.Character:FindFirstChild("HumanoidRootPart")
     if LowerTorso then
        LowerTorso.CFrame = CFrame.new(part.CFrame.p)
    end
end)

script.Parent.MouseButton1Click:Connect(function(Click)
	script.Parent.Parent.Parent.Enabled = false
end)

local human = part.Parent:FindFirstChild("Humanoid") --Check if it is player
    local player = game.Players:GetPlayerFromCharacter() --Get actual player object

    if human then
        for i,v in pairs (part.Parent:GetChildren()) do --Look inside player
            if v:IsA("Tool") and v.Name == "Lantern" then --If they are holding the tool we want
                v:Destroy()
            end
        end

        for i,v in pairs (player.Backpack:GetChildren()) do
            if v.Name == "Lantern" then
                v:Destroy() --Search backpack for tool as well
            end
        end
    end



2 comments

0

easy, check the character or the players backpack

0

How would I do that though?

2 answers

✓ Accepted answer

I'm confused on why you did "human = part.Parent:FindFirstChild("Humanoid")". Part is your variable name for the cabin. By the way, you don't have to destroy the tools. Just clear the backpack like this:

local part = workspace.Cabin
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local LowerTorso = plr.Character:FindFirstChild("HumanoidRootPart")
     if LowerTorso then
        LowerTorso.CFrame = CFrame.new(part.CFrame.p)
    end
end)

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent.Enabled = false
end)

    if plr then
	player.Backpack:ClearAllChildren() -- Clears backpack
end

Hope this helps!

2 comments

0

It didn't work, could you maybe explain how or where I would use that script?

0

Yeah, I just edited the Script. I included your original one so you know where to put it.

So you could use

game.Players.PlayerYouWant.BackPack:ClearChildren()

This discussion is preserved as it was. New answers, comments, and votes are closed.