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

Assign Class script not working?

Asked by 8 years ago

So I edited this Assign Class script to fit my game and weapons. It is a Local Script, and works fine in ROBLOX Studio solo, but whenever I go to test in on a server or in game, it doesn't work.

Basically what happens is it will give the player the tool, but nothing happens when I try to equip it. The gun scripts I have are pretty "fancy" as well, and are supposed to put the gun on the player's back if it is unequipped (and have a special equipped animation). However, as I mentioned, nothing happens, and whenever I equip the gun (which is not even there), my player's arms don't even move.

Here is the script:

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

Output doesn't say anything either.

0
Nah bud. The problem is that roblox LocalScripts load before the character does. So, you gotta tell the script to wait for the character to load. Try this by putting it on line one with everything else below it: repeat wait() until game.Players.LocalPlayer.Character repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(game.Workspace) wait(1 / 20) iDev_Percy 45 — 8y
0
That is a long time to wait lol. Like near a month DeveloperSolo 370 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

I suggest storing the tools in the ReplicatedStorage, meaning that you'll have to alter the script a bit. The problem is, that when the parts in tools are parented to PlayerGui, Physics are applied on them causing them to fall through the map (Cause they are CanCollide false) and then getting deleted.

Hope it helps, but might be wrong!

0
Well the player gui itself is in ReplicatedStorage. Should I take the tools out of the GUI and leave them in ReplicatedStorage? BartyCrouchJunior 57 — 8y
0
Yes (Sorry for late answer) Dolphinous 36 — 8y
Ad

Answer this question