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

How do I clone a weapon to only the player who had it before they died starterpack?

So this script clones a weapon that the player had before death to the WHOLE game's starter pack, but I need it to only be cloned to the person that had it before they died starter pack

local wm = Instance.new("Model")
wm.Name = "Weaps"

function give(weap, player) 
    --return if they allready have a copy
    for _, w in ipairs(player.Weaps:GetChildren()) do
        if w.Name == weap.Name then return end
    end
    --return if the weaps is a startpack one
    for _, w in ipairs(game.StarterPack:GetChildren()) do
        if w.Name == weap.Name then return end
    end
    --add it to thier weapons
    weap:clone().Parent = game.StarterPack
end

game.Players.ChildAdded:connect(function(p)
    wm:clone().Parent = p
    wait()
    p.Character.ChildAdded:connect(function(wep)
        if wep.className == "Tool" then
            give(wep, p)
        end
    end)
    p.Changed:connect(function(pr)
        if pr == "Character" then
            for _, w in ipairs(p.Weaps:GetChildren()) do
                w:clone().Parent = p.Backpack
            end
            p.Character.ChildAdded:connect(function(wep)
                if wep.className == "Tool" then
                    give(wep, p)
                end
            end)
        end
    end)
    p.Backpack.ChildAdded:connect(function(h)
        if h.className == "HopperBin" then
            give(h, p)      
        end
    end)
end)


1 comment

0

Use a LocalScript, please use the PlayerAdded signal instead of ChildAdded.

1 answer

✓ Accepted answer

All players have StarterGear, which is similar to StarterPack, but it's not a service and only clones to that player's backpack.

I'm not sure how or when the player gets the tool, so i'll make a script for general use of this:

local Players = game:GetService('Players')

local Tool = game:GetService('ServerStorage'):WaitForChild('Tool')

Players.PlayerAdded:Connect(function(plr)
	repeat wait() until plr and plr:FindFirstChild('StarterGear')
	local newTool = Tool:Clone()
	newTool.Parent = plr.StarterGear
	--putting it in startergear for the first time may not show up in backpack, so this will make sure it does.
	if not plr.Backpack:FindFirstChild(newTool.Name) then
		Tool:Clone().Parent = plr.Backpack
	end
end)

3 comments

0

thanks!

0

i tried that but it didnt work when the player resets do you know how to make it work when the player resets also?

0

it should work, since StarterGear is supposed to clone each time they respawn

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