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

How can I change this script so instead of having to type "r", players just spawn with the gear?

Asked by 4 years ago

So I'm working on a game where every time a player spawns, I want them to spawn with a different set on randomized Gear. I've tried a couple different ways to make this happen, and thus far the best/closest thing I've found to work is magiccube3's script, but on hers, she makes it so every time a player chats "r" it'll give them the gear:

gears = {99797357, 99797381, 99797403, 99797327, 94794774, 99641902, 99610601, 99119158, 99119198, 97161241, 99254437, 99254358, 99119261, 99254241, 99119240, 83021197, 99254203, 99254164, 92142841, 87361662, 99130630, 99033296, 98411393, 98411436, 98970218, 98341183, 98253651, 98411325, 98253626, 98253592, 98346415, 13745494, 98253569, 98219158, 97932897, 97885552, 97885508, 97885572, 97885289, 97886188, 97756645, 97712291, 97311482, 97161262, 97161295, 96669943, 96669687}


function onMsg(msg, ply)
 if msg == "r" then
for i = 1,5 do
        local model = game:GetService("InsertService"):LoadAsset(gears[math.random(#gears)])
        for _,v in pairs(model:GetChildren()) do
             if v:IsA("Tool") or v:IsA("HopperBin") then
                    v.Parent = ply.Backpack
                end
            end
        end
    end
end



game.Players.PlayerAdded:connect(function(ply)

    ply.Chatted:connect(function(msg) onMsg(msg, ply) end)

end)


for _,ply in pairs(game.Players:GetPlayers()) do

    ply.Chatted:connect(function(msg) onMsg(msg, ply) end)

end

So my question is, how would I be able to change this script to make it so that, instead of having to type "r" to get the gear, players would spawn with a randomized backpack of gear (which also changes when the die and respawn)

1 answer

Log in to vote
0
Answered by 4 years ago

You can use CharacterAdded

gears = {99797357, 99797381, 99797403, 99797327, 94794774, 99641902, 99610601, 99119158, 99119198, 97161241, 99254437, 99254358, 99119261, 99254241, 99119240, 83021197, 99254203, 99254164, 92142841, 87361662, 99130630, 99033296, 98411393, 98411436, 98970218, 98341183, 98253651, 98411325, 98253626, 98253592, 98346415, 13745494, 98253569, 98219158, 97932897, 97885552, 97885508, 97885572, 97885289, 97886188, 97756645, 97712291, 97311482, 97161262, 97161295, 96669943, 96669687}






game.Players.PlayerAdded:connect(function(ply)
    ply.CharacterAdded:Connect(function()
        for i = 1,5 do
            local model = game:GetService("InsertService"):LoadAsset(gears[math.random(#gears)])    
            for _,v in pairs(model:GetChildren()) do
                if v:IsA("Tool") or v:IsA("HopperBin") then
                    v.Parent = ply.Backpack
                end
            end
        end
    end)
end)

for i,v in pairs(game.Players:GetPlayers()) do
    v.CharacterAdded:Connect(function()
        for i = 1,5 do
            local model = game:GetService("InsertService"):LoadAsset(gears[math.random(#gears)])    
            for _,v in pairs(model:GetChildren()) do
                if v:IsA("Tool") or v:IsA("HopperBin") then
                    v.Parent = ply.Backpack
                end
            end
        end
    end)
end)

0
I appreciate the quick responce! I edited the script to fit what you showed but unfortunetly it isn't working, any other ideas? Cynical_Potatoe 5 — 4y
0
Oh, nevermind! I figured it out. Thank you very much for your help! Cynical_Potatoe 5 — 4y
0
Welcome, Make sure to accept the answer if it helped! mybituploads 304 — 4y
Ad

Answer this question