yworld101
(yworld101)
March 6, 2021, 8:45pm
#1
So I created guis that pops up at the start of the game in which you chose what team you want to be on (very similar to jailbreak). It works perfectly fine one player but when I test it locally, sometimes the guis dont show up. I understand this is a problem with my script being a normal script, but I need help figuring out what would go in a local script and what should stay in the normal script. Also, do these scripts go in replicated storage or server storage.
local TeamService = game:GetService(“Teams”)
local playerService = game:GetService(“Players”)
local playerAlreadyJoined = false
playerService.PlayerAdded:Connect(function( p)
p.CharacterAdded:Connect(function(c)
if playerAlreadyJoined == false then
local PoliceButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Police")
local PrisonerButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Prisoner")
local Blur = game.Lighting.Blur
local StartGui = p:WaitForChild("PlayerGui"):WaitForChild("StartGui")
local ui = p:WaitForChild("PlayerGui"):WaitForChild("UI")
wait()
c:Remove()
game.Players.CharacterAutoLoads = false
StartGui.Enabled = true
Blur.Size = 24
--PoliceJoinCommands--------------------------------------------------------------------
PoliceButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Bright blue")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
local Keycard = game.ServerStorage.Keycard:Clone()
Keycard.Parent = p:WaitForChild("Backpack")
end)
--PrisonerJoinCommands-------------------------------------------------------------------
PrisonerButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Br. yellowish orange")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
end)
end
end)
end)
There were some weird characters, but I fixed.
Try this:
local TeamService = game:GetService("Teams")
local playerService = game:GetService("Players")
local playerAlreadyJoined = false
playerService.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
if playerAlreadyJoined == false then
local PoliceButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Police")
local PrisonerButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Prisoner")
local Blur = game.Lighting.Blur
local StartGui = p:WaitForChild("PlayerGui"):WaitForChild("StartGui")
local ui = p:WaitForChild("PlayerGui"):WaitForChild("UI")
wait()
c:Remove()
game.Players.CharacterAutoLoads = false
StartGui.Enabled = true
Blur.Size = 24
--PoliceJoinCommands--------------------------------------------------------------------
PoliceButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Bright blue")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
local Keycard = game.ServerStorage.Keycard:Clone()
Keycard.Parent = p:WaitForChild("Backpack")
end)
--PrisonerJoinCommands-------------------------------------------------------------------
PrisonerButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Br. yellowish orange")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
end)
end
end)
end)
You cannot detect a click in a serverscript fromwhat I know
yworld101
(yworld101)
March 6, 2021, 8:58pm
#4
Ya this is my first post so idk why my characters got messed up on it but the problem is not a syntax error
yworld101
(yworld101)
March 6, 2021, 8:59pm
#5
It seems to work single player but idk locally
try this:
game.Players.PlayerAdded:Connect(function(p)
local playerAlreadyJoined = false
p.CharacterAdded:Connect(function(c)
if playerAlreadyJoined == false then
local PoliceButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Police")
local PrisonerButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Prisoner")
local Blur = game.Lighting.Blur
local StartGui = p:WaitForChild("PlayerGui"):WaitForChild("StartGui")
local ui = p:WaitForChild("PlayerGui"):WaitForChild("UI")
wait()
c:Remove()
game.Players.CharacterAutoLoads = false
StartGui.Enabled = true
Blur.Size = 24
--PoliceJoinCommands--------------------------------------------------------------------
PoliceButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Bright blue")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
local Keycard = game.ServerStorage.Keycard:Clone()
Keycard.Parent = p:WaitForChild("Backpack")
end)
--PrisonerJoinCommands-------------------------------------------------------------------
PrisonerButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Br. yellowish orange")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
end)
end
end)
end)
yworld101
(yworld101)
March 6, 2021, 9:03pm
#7
So far it seems to work but if a player joins in on the middle of a game wouldn’t it glitch? So wouldn’t I need to use local scripts too?
probably not also, I made one edit and removed one line, see the screenshot below.
Put a Server Script in StarterGui:
local TeamService = game:GetService("Teams")
local playerService = game:GetService("Players")
playerService.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
local playerAlreadyJoined = false
if playerAlreadyJoined == false then
local PoliceButton = script.Parent:WaitForChild("StartGui"):WaitForChild("Police")
local PrisonerButton = script.Parent:WaitForChild("StartGui"):WaitForChild("Prisoner")
local Blur = game.Lighting.Blur
local StartGui = script.Parent:WaitForChild("StartGui")
local ui = script.Parent:WaitForChild("UI")
wait()
c:Remove()
game.Players.CharacterAutoLoads = false
StartGui.Enabled = true
Blur.Size = 24
--PoliceJoinCommands--------------------------------------------------------------------
PoliceButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Bright blue")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
local Keycard = game.ServerStorage.Keycard:Clone()
Keycard.Parent = p:WaitForChild("Backpack")
end)
--PrisonerJoinCommands-------------------------------------------------------------------
PrisonerButton.MouseButton1Down:Connect(function()
p.TeamColor = BrickColor.new("Br. yellowish orange")
StartGui.Enabled = false
Blur.Size = 0
game.Players.CharacterAutoLoads = true
ui.Enabled = true
playerAlreadyJoined = true
p:LoadCharacter()
end)
end
end)
end)
It may make no sense. But you won’t understand without trying.
yworld101
(yworld101)
March 6, 2021, 9:10pm
#10
Nah this glitched it so some of the blurs and guis didnt show up
yworld101
(yworld101)
March 6, 2021, 9:12pm
#11
The script dosent work some parts dont show up
Also the blur, because it’s in a serverscript. It will be for everyone the blur. Start watching some tutorials first. get some info abt some fucntions etc
yworld101
(yworld101)
March 6, 2021, 9:14pm
#13
Thats why I asked shouldnt it be local script?
Edit: not the whole script just part of it
1 Like
RFL890
(GeorgeCatherington)
March 7, 2021, 12:16am
#14
A Server script in a Client gui doesn’t work I think
Yeah, use remoteevents that should work
yworld101
(yworld101)
March 8, 2021, 12:09am
#16
Ok thanks I will try that-----
yworld101
(yworld101)
March 8, 2021, 12:10am
#17
It works just not on multiplayer games