I want to have a Round Script that teleports people to the map, counts down, and when it ends give the winners wins and then teleport them to the lobby (also if its the first win it gives them a badge.)
The problem is at the end where it teleports them and gives wins to the winners (Important: The real issue is that the player still gets a win when they loose and die)
I was searching on the Dev Forum I couldn’t find anything that would help
Part where I have the issue:
for i, player in pairs (playingplayers) do
local gamea = game.Teams.Playing
if player.Team == playingteam then
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
end
if player.leaderstats.Wins.Value >= 1 then
local badgeservice = game:GetService("BadgeService")
local id = (2129235295)
local plr = player
badgeservice:AwardBadge(plr.UserId, id)
end
local Character = player.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character then
HumanoidRootPart.CFrame = Lobby.TeleportPoint.CFrame
wait(1)
player.Team = lobbyteam
end
end
if player.Team == playingteam then
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
end
This looks like it gives the wins to any player on the player team anyways, even if they lose. It doesn’t look like there’s a check for if the player lost. Is there a check somewhere else in the script? Is there a ‘Dead’ team?
--Variables
local Lobby = game.Workspace.Lobby
local Maps = game.ReplicatedStorage.Maps:GetChildren()
local Disasters = game.ReplicatedStorage.DisasterRemotes:GetChildren()
local Status = game.ReplicatedStorage.Status
local lobbyteam = game:GetService("Teams").Lobby
local playingteam =game:GetService("Teams").Playing
local intermission = 10
local gameLength = 60
-- Game Loop
while true do
-- intermission
for i = intermission, 0, -1 do
Status.Value = "Intermission: "..i
task.wait(1)
end
-- Map Selector
local ChosenMap = Maps [math.random(1, #Maps)]
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = game.Workspace.SelectedMap
Status.Value = "Map: "..ClonedMap.Name
task.wait(1)
-- Teleports to the map
for _, v in pairs(game.Players:GetPlayers()) do
local Character = v.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local gamee = game.Teams.Playing
if Character then
HumanoidRootPart.CFrame = game.Workspace.SelectedMap:FindFirstChildWhichIsA("Model").TeleportPoint.CFrame
v.Team = playingteam
end
end
-- Random Disaster
local ChosenDisaster = Disasters [math.random(1, #Disasters)]
local hint = game.ReplicatedStorage.Hint
local hintevent = game.ReplicatedStorage.HintEvent
local risingevent = game.ReplicatedStorage.DisasterRemotes.RisingLava
local tsunamievent = game.ReplicatedStorage.DisasterRemotes.Tsunami
local meteorevent = game.ReplicatedStorage.DisasterRemotes.Meteor
if ChosenDisaster == game.ReplicatedStorage.DisasterRemotes.Tsunami then
local game1 = game.Teams.Lobby
tsunamievent:Fire()
gameLength = 30
print("The game has started (Rising Lava)")
wait(5)
hint.Value = "A Tsunami has been spotted! Seek hight shelter immediately!"
hintevent:FireAllClients()
print("The game has started (Tsunami)")
elseif ChosenDisaster == game.ReplicatedStorage.DisasterRemotes.Meteor then
local game1 = game.Teams.Lobby
meteorevent:Fire()
gameLength = 45
print("The game has started (Rising Lava)")
risingevent:Fire()
wait(5)
hint.Value = "A Meteor Shower has been spotted! Seek shelter immediately, and avoid getting hit!"
hintevent:FireAllClients()
elseif ChosenDisaster == game.ReplicatedStorage.DisasterRemotes.RisingLava then
local game1 = game.Teams.Lobby
risingevent:Fire()
gameLength = 45
print("The game has started (Rising Lava)")
wait(5)
hint.Value = "Rising Lava has been spotted! Seek high shelter immediately!"
hintevent:FireAllClients()
end
task.wait(5)
-- Game Time
for i = gameLength, 0, -1 do
Status.Value = "Game: "..i
task.wait(1)
Status.Value = "Game Over"
end
local playingplayers = playingteam:GetPlayers()
for i, player in pairs (playingplayers) do
local gamea = game.Teams.Playing
if player.Team == playingteam then
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
end
if player.leaderstats.Wins.Value >= 1 then
local badgeservice = game:GetService("BadgeService")
local id = (2129235295)
local plr = player
badgeservice:AwardBadge(plr.UserId, id)
end
local Character = player.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character then
HumanoidRootPart.CFrame = Lobby.TeleportPoint.CFrame
wait(1)
player.Team = lobbyteam
end
end
-- Destroys Map
wait(3)
ClonedMap:Destroy()
end
I feel like you should use variables/stats for detecting if the player has lost/died in the current round instead of depending on teams. That might make it better.
Yeah. When a new round starts, BoolValue.Value would be set to false because the player is not dead yet, meaning it’s false. When the player loses or dies, it would be set to true.
so basically i added 2 folders in ReplicatedStorage one is “Playerdeadevents” other one is “Playerdeadvalues” (Bool Values)
also added another Script in ServerScriptService which is
local event2 = game.ReplicatedStorage.ded -- Outside Event (for server)
local lobbyteam = game.Teams.Lobby -- the team
game:GetService("Players").PlayerAdded:Connect(function(player)
local boolvalue = Instance.new("BoolValue") -- Adds Boolvalue when a player joins
boolvalue.Name = player.Name -- sets name of bool to players name
boolvalue.Parent = game.ReplicatedStorage.Playerdeadvalues -- sets parent to the "Playerdeadvalues" folder
local event = Instance.new("RemoteEvent") -- does the samething as above except its a RemoteEvent
event.Name = player.Name
event.Parent = game:GetService("ReplicatedStorage").Playerdeadevents
end)
event2.OnServerEvent:Connect(function(player) -- Sets the value to true (in server)
local event = game.ReplicatedStorage.Playerdeadevents:FindFirstChild(player.Name)
local value = game.ReplicatedStorage.Playerdeadvalues:FindFirstChild(player.Name)
value.Value = true
wait(2.5)
player.Team = lobbyteam -- sets team
end)
and a localscript in StarterCharacterScripts
local player = game:GetService("Players").LocalPlayer -- the player
local character = player.Character -- character
local hum = character:WaitForChild("Humanoid") -- humanoid
local value = game:GetService("ReplicatedStorage").Playerdeadvalues:FindFirstChild(player.Name) -- the boolvalue
local event = game:GetService("ReplicatedStorage").Playerdeadevents:FindFirstChild(player.Name) -- the remote event
local event2 = game:GetService("ReplicatedStorage").ded -- outside event
local lobbyteam = game:GetService("Teams").Lobby -- lobby team
hum.Died:Connect(function() -- fires when character dies
player.Team = lobbyteam -- sets team
if value then -- checks if the value exists
value.Value = true -- sets the value to true (from client)
event:FireServer() -- fires RemoteEvent
event2:FireServer(player) -- Fires Outside Event
end
end)
and then modified my round script so it works with my new changes