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

Tools children dissapears on pick up?

Asked by
Kryddan 261 Moderation Voter
9 years ago

I got this script that when i press "g" it looks for a tool that is equipped and it drops it and then when i walk over it i pick it up again. There is only one problem though and that is when i pick it up all the children of the tool is gone like the Handle,Script,sounds

it is in a localscript btw in starterpack

local player = game.Players.LocalPlayer
local character = player.Character
local mouse = player:GetMouse()


function droppa(pos)
local handle = character:FindFirstChild("Handle", true)
if handle.Parent.ClassName == "Tool" then
local gun = handle.Parent
    local drop = handle:Clone() 
    drop.Parent = game.Workspace
    drop.CFrame = CFrame.new(pos)
    drop.Anchored = false
    drop.CanCollide = true
    drop.Touched:connect(function(hit)  
        gun:remove()
        local humanoid = hit.Parent:FindFirstChild("Humanoid")  
        if humanoid and humanoid.Health > 0 then        
            local backpack = player:WaitForChild("Backpack")    
            if backpack then        
                drop:remove()   
                    local weapon = gun
                    weapon.Parent = backpack
                end
            end
        end)
    else
    droppa(player.Character.Torso.Position - Vector3.new(0,1,4))
    end
end



mouse.KeyDown:connect(function(key)
    key:lower()
    if key == "g" then
        droppa(player.Character.Torso.Position - Vector3.new(0,1,4))
    end
end)

EDIT: i found the answer but now i got another problem. The first problem was gun:remove() on line 19 and i used that to remove the tool from my backpack but i dont know a better way of doing this. another problem i got now is that i get this from the output: Players.Player1.Backpack.LocalScript:11: stack overflow when i press "g" after the first time i picked the tool up.

Answer this question