Hi guys, I’m currently making a game but because I’m not a scripter so have been hitting some dead ends. I was just trying to make it so in the intermission phase of the game, players can choose their teams and characters then when the game starts they will spawn accordingly. I’m also making this using script in serverscriptservice. Here is the code for the game start:
local function StartGame()
workspace:SetAttribute(“GameRunning”, true)
print(“Start game”)
game.Players.PlayerAdded:Connect(function(plr)
if plr.Team == "Zombie" then
SpawnZombie()
elseif plr.Team == "Civ" then
SpawnCiv()
elseif plr.Team == "Police" then
SpawnPolice()
end
end)
end
Here script for intermission:
function Intermission()
workspace:SetAttribute(“GameRunning”, false)
re.OnServerEvent:Connect(function(plr, teamname)
if teamname == "Zombie" then
plr.Team = game.Teams.Zombies
elseif teamname == "Civ" then
plr.Team = game.Teams.Civilians
elseif teamname == "Police" then
plr.Team = game.Teams.Polices
end
end)
end
I have been searching online many times but to no avail I can’t find anything useful or maybe I don’t understand but I hope someone can help me become better. Thanks a lot!
I added some stuff to your script; this should help you. Just make sure you have the RemoteEvent in ReplicatedStorage. Also, ensure that you have the SpawnZombie() , SpawnCiv() , and SpawnPolice() functions defined somewhere in your code. These functions should handle the actual spawning logic for each team.
Intermission Script (ServerScriptService):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local re = Instance.new("RemoteEvent")
re.Name = "TeamSelectionEvent"
re.Parent = ReplicatedStorage
function Intermission()
workspace:SetAttribute("GameRunning", false)
re.OnServerEvent:Connect(function(plr, teamname)
local team = game.Teams[teamname]
if team then
plr.Team = team
end
end)
end
Intermission()
Game Start Script (ServerScriptService):
local function StartGame()
workspace:SetAttribute("GameRunning", true)
print("Start game")
game.Players.PlayerAdded:Connect(function(plr)
if plr.Team == game.Teams.Zombies then
SpawnZombie()
elseif plr.Team == game.Teams.Civilians then
SpawnCiv()
elseif plr.Team == game.Teams.Polices then
SpawnPolice()
end
end)
end
StartGame()