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

My gui script works perfectly fine in studio, but not a server test or ingame?

Asked by 6 years ago
Edited 6 years ago

Hi there, I have a script for assigning weapons that works perfectly fine in roblox studio, but not in the actual game, or the server test mode. Any help would from coders more experienced than myself would be very appreciated.

When I join the game in any way except for solo test, the GUI does not appear at all.

game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
player = game.Players.LocalPlayer
backpack = player.Backpack
script.Parent.Main.Visible = true
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
    script.Parent.Title.Visible = false
end

function onHumanoidDied(humanoid, player)
    script.Parent.Main.Visible = true
    script.Parent.Title.Visible = true
    end

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

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Made a few fixes, since you were using some deprecated code (e.g. remove(), connect())

player = game:GetService("Players").LocalPlayer
backpack = player.Backpack
script.Parent.Main.Visible = true
function chooseClass(class)
    for i, v in pairs(backpack:GetChildren()) do v:Destroy() end
    for i, v in pairs(class:GetChildren()) do
        if v:IsA("Tool") or v:IsA("HopperBin") then
            v:Clone().Parent = backpack
        end
    end

    script.Parent.Main.Visible = false
    script.Parent.Title.Visible = false
end

function onHumanoidDied()
    script.Parent.Main.Visible = true
    script.Parent.Title.Visible = true
end

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

player.Humanoid.Died:Connect(onHumanoidDied)

You shouldn't be using HopperBins, they are deprecated. If this answer helped you, please accept it and upvote.

0
Thank you for the detailed response, I had no idea I was so out of date! The new script works perfectly in Studio as well, but absolutely refuses to show up in-game. hulabee 7 — 6y
0
I edited it, this should work. If it still doesn't, please tell me if there are any errors. Zenith_Lord 93 — 6y
0
No luck, It still doesnt show up in the game, despite the console not returning any relevant errors. hulabee 7 — 6y
0
hm Zenith_Lord 93 — 6y
View all comments (5 more)
0
Could you elaborate on what you want to happen? Zenith_Lord 93 — 6y
0
I can. In test mode, a GUI appears when a player spawns in for the first time, prompting them to select a class. Once a class is selected, if it functions correctly, it will empty the player's backpack, assign a morph to the player, assign the class's weapons, and hide itself. hulabee 7 — 6y
0
The script I posted is under a ScreenGui named "WeaponChooser", next to all of the textlabels with scripts inside of each respective one. hulabee 7 — 6y
0
Do you want the gui to show only for the first time they spawn, and never again (until they rejoin)? Zenith_Lord 93 — 6y
0
Eventually, but for now I would like it to re-appear after the character respawns. hulabee 7 — 6y
Ad

Answer this question