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

I made a GUI that opens when you start the game and it works fine in studio but not in a server?

I am working on a game that has a gui to select a team at the start of a game as well as a frame under the same parent in that gui. The team change buttons trigger the player to switch teams as well as make the teamchange frame not visible and classSelect frame visible. I also have a text box in my teamchange frame that displays how many players are on a team, but this shows up as the text that I have that isn't affected by code (so just "…"). All of the scripts are inside all the buttons and labels and the frames are inside a gui inside of startergui.

If it helps, here is the code inside of the teamchange button

local plr = script.Parent.Parent.Parent.Parent.Parent.Name
script.Parent.MouseButton1Click:connect(function() 
	game.Players[plr].TeamColor = BrickColor.new("Really red") 
	game.Workspace[plr].Humanoid.Health = "0" 
	wait(5)
	script.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.ClassFrame.Visible = true
	script.Parent.Parent.Parent.ZoneWarning.Visible = true
end)

1 comment

0

What is line 1?

3 answers

###Jesus! You don’t need so many .Parent’s!

local plr = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    plr.TeamColor = BrickColor.new"Really red"
    plr.Character.Humanoid.Health = 0
end)

###Basic fixes to make life easy.

-- You can't access or operate guis using a server script. Use localscript and paste your old script --into the local script
--[[ btw, incap is right. You don't need a ton of use of "parents" all the time. Define them using variables]]
-- paste into localscript
local plr = script.Parent.Parent.Parent.Parent.Parent.Name
script.Parent.MouseButton1Click:connect(function() 
    game.Players[plr].TeamColor = BrickColor.new("Really red") 
    game.Workspace[plr].Humanoid.Health = "0" 
    wait(5)
    script.Parent.Parent.Visible = false
    script.Parent.Parent.Parent.ClassFrame.Visible = true
    script.Parent.Parent.Parent.ZoneWarning.Visible = true
end)

Have you tried turning it off and back on again?

1 comment

0

This should be a comment.

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