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

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

Asked by 6 years ago

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)
0
What is line 1? User#19524 175 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

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.

Ad
Log in to vote
0
Answered by
Delude_d 112
6 years ago
Edited 6 years ago
-- 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)
Log in to vote
-1
Answered by 6 years ago

Have you tried turning it off and back on again?

0
This should be a comment. User#19524 175 — 6y

Answer this question