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
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.