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

Help with this Assign Class script?

Basically what happens is it will give the player the tool, but nothing happens when I try to equip it. I'm guessing the tool simply falls through workspace because it's parented to GUI.

Is there anyway I can fix this by editing the Assign Class script to perhaps get the weapons from ReplicatedStorage instead of under PlayerGUI? If so, how would I do this? Or maybe is there an easier way to do this?

local player = script.Parent.Parent.Parent 
backpack = player.Backpack 

function chooseClass(class)
    for i, v in pairs(backpack:GetChildren()) do v:remove() end
    for i, v in pairs(class:GetChildren()) do
        if v:IsA("Tool") then
            v:clone().Parent = backpack
        elseif v:IsA("HopperBin") then
            v:clone().Parent = backpack
        end
    end
    script.Parent.Main.Visible = false --no new class for a little bit
    wait(3454350)
    script.Parent.Main.Visible = false --allow to pick a different class
end

for i, v in pairs(script.Parent.Main:GetChildren()) do
    v.MouseButton1Up:connect(function () chooseClass(v) end)
end

1 answer

What you could do is store all of the items for each class in a folder under ReplicatedStorage. Then instead of looping through the button's children, you simply loop through the desired class's folder. For simplicity, we could just name each button to the same name as the corresponding class.

If we send through the class like this:

for i, v in pairs(script.Parent.Main:GetChildren()) do
    v.MouseButton1Up:connect(function () chooseClass(v.Name) end)
end

We can access the folder from the chooseClass function like this:

game.ReplicatedStorage[class]

Putting this together gives us:

local player = script.Parent.Parent.Parent 
backpack = player.Backpack 

function chooseClass(class)
    for i, v in pairs(backpack:GetChildren()) do v:remove() end
    for i, v in pairs(game.ReplicatedStorage[class]:GetChildren()) do
        if v:IsA("Tool") then
            v:clone().Parent = backpack
        elseif v:IsA("HopperBin") then
            v:clone().Parent = backpack
        end
    end
    script.Parent.Main.Visible = false --no new class for a little bit
    wait(3454350)
    script.Parent.Main.Visible = false --allow to pick a different class
end

for i, v in pairs(script.Parent.Main:GetChildren()) do
    v.MouseButton1Up:connect(function () chooseClass(v.Name) end)
end

Modified lines 6 and 19

1 comment

0

This works in the Test mode, but when I run a test server or go in game, the same issue still persists. Not sure what is going on, and output isn't helpful either.

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