The error is likely something I explained in the post, but did not give a proper piece of code for.
You need to insert an intvalue into the player’s character, which you can do like this:
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local stageValue = Instance.new("IntValue", char)
stageValue.Name = "Stage"
end
end)
The intvalue needs to be inserted into the player’s character. Without having the full script as it is right now, the only guess I could make is that you placed the piece of code I gave you after the while true do loop. If you could give the current script, I can help a bit further though.
Sorry if I was making it unclear but, PlayerVal and PlayerNum are where you put the tag value according to the player. So if I had the tag value in the leaderboard I would do something like this,
PlayerVal = v.leaderstats.tag.Value -- the value of the tag
PlayerNum = v.leaderstats.tag.Value -- the value of the tag
v is the player, leaderstats.tag.Value is getting the value. local pn = 6 was put in for testing purposes so I knew that the script actually worked.
Yes I put in after the while true do loop, here is the full script:
ServerStorage = game:GetService(“ServerStorage”)
ReplicatedStorage = game:GetService(“ReplicatedStorage”)
Players = game:GetService(“Players”)
local Team = game:GetService(“Teams”)
local Contestants = game.Teams.Contestants
local Spectators = game.Teams.Spectators
local Completed = game.Teams.Completed
local cs = game:GetService(“CollectionService”)
Maps = ServerStorage:WaitForChild(‘Maps’):GetChildren()
Status = ReplicatedStorage:WaitForChild(‘Status’)
while true do
--Intermission
local Countdown = 10 -- ten second intermission, make this as long as you want
repeat wait(1)
Countdown = Countdown - 1
Status.Value = 'Intermission : '..Countdown
until Countdown <= 0
--Choose the map.
Status.Value = 'Choosing Map...'
local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
local RandomSpawn = Spawns[math.random(1, #Spawns)]
local LobbySpawns = game.Workspace.Lobby:FindFirstChild('LobbySpawns'):GetChildren()
local RandomLobbySpawn = LobbySpawns[math.random(1, #LobbySpawns)]
wait(5) -- little pause, make this as long as you want
ChosenMap.Parent = workspace
Status.Value = 'Next Map Is: '
wait(2) -- little pause, make this as long as you want
Status.Value = ChosenMap.Name
wait(2) -- little pause, make this as long as you want
--teleport the players
for _, Player in pairs(Players:GetChildren())do
if Player.Character and Player.Character:FindFirstChild('Humanoid') then
Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
end
end
for _, Player in pairs(Players:GetChildren())do
Player.Team = Contestants
end
-- Reassign countdown based on chosen map's Duration value
Countdown = ChosenMap:FindFirstChild("Duration").Value
repeat wait(1)
Countdown = Countdown - 1
local minutes = math.floor(Countdown / 60)
local seconds = math.floor(Countdown % 60)
Status.Value = string.format("Time left : %.2d:%.2d", minutes, seconds)
until Countdown <= 0
--Teleport back to lobby
for _, Player in pairs(Players:GetChildren())do
if Player.Character and Player.Character:FindFirstChild('Humanoid') and Player.Team == Contestants then
Player.Character.HumanoidRootPart.CFrame = RandomLobbySpawn.CFrame
end
end
for _, Player in pairs(Players:GetChildren())do
Player.Team = Completed
end
local slowestPlayer = nil
local lowestStage = math.huge -- This will ensure that the first check will always pass
for _, player in pairs(Players:GetPlayers()) do
local char = player.Character
if not char then continue end
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local stageValue = Instance.new("IntValue", char)
stageValue.Name = "Stage"
end)
end)
local stage = char.Stage.Value
if stage < lowestStage then
lowestStage = stage
slowestPlayer = player
end
end
for _, Player in pairs(Players:GetChildren())do
slowestPlayer.Team = Contestants
end
Status.Value = 'The eliminated player is: '
ChosenMap:Destroy()
You should put it in before the while true do loop, otherwise lua won’t ever execute those lines of code because it keeps looping in the while true do loop.
I didn’t know that So i put it before the loop, and also i corrected the part that I had written alone, which was wrong (I wrote the wrong team):
for _, Player in pairs(Players:GetChildren())do
slowestPlayer.Team = Spectators
end
Then I tried again, and now there are no errors!
The only problem is that when I reached the end of the obby and was teleported to lobby, my alt account was teleported too /:
This is the script of the “Teleport” part, which is the last one in the obby, which teleports to lobby:
Players = game:GetService(“Players”)
local LobbySpawns = game.Workspace.Lobby:FindFirstChild(‘LobbySpawns’):GetChildren()
local RandomLobbySpawn = LobbySpawns[math.random(1, #LobbySpawns)]
script.Parent.Touched:Connect(function()
for _, Player in pairs(Players:GetChildren())do
if Player.Character and Player.Character:FindFirstChild(‘Humanoid’) then
Player.Character.HumanoidRootPart.CFrame = RandomLobbySpawn.CFrame
end
end
end)