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

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

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

✓ Accepted answer

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.

9 comments

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.

0

I edited it, this should work. If it still doesn't, please tell me if there are any errors.

0

No luck, It still doesnt show up in the game, despite the console not returning any relevant errors.

0

hm

0

Could you elaborate on what you want to happen?

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.

0

The script I posted is under a ScreenGui named "WeaponChooser", next to all of the textlabels with scripts inside of each respective one.

0

Do you want the gui to show only for the first time they spawn, and never again (until they rejoin)?

0

Eventually, but for now I would like it to re-appear after the character respawns.

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