In Legends of Speed, They show the top players in order depending on how made it to the top first. I want to do something like this. How would I have it updating the player’s gui? Sorry if this is a simple question . . . I do not have much knowledge of local or module scripts
I will try and figure out how to do this. Please, any help would be greatly appreciated!
They loop through all the players and see who has the highest score they then check the second highest score and finally the third highest score.
There’s 2 solutions for this
- You can add winners into a table then get their positions at the end.
local winners = {}
local winPart = workspace.Part
winPart.Touched:Connect(function(obj)
local model = obj:FindFirstAncestorWhichIsA('Model')
local player = game.Players:GetPlayerFromCharacter(model)
if model and player then
winners[#winners + 1] = player
end
end)
Then to simply get the player in 1st place, you can do:
local firstPlace = winners[1]
- i forgot the 2nd solution
1 Like
Thank you! I will try this! I will let you know if this works
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local debounce = false
local players = {}
--make chatbot
if not ChatService:GetChannel("All") then
while true do
local ChannelName = ChatService.ChannelAdded:Wait()
if ChannelName == "All" then
break
end
end
end
local serverchat = ChatService:AddSpeaker("Server")
function chat(text)
serverchat:JoinChannel("All")
serverchat:SayMessage(text, "All")
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
debounce = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player.leaderstats.Level.Value == 10 then
player:LoadCharacter()
player.leaderstats.Level.Value = 0
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 200
end
if #players < 0 then
table.insert(players, player)
print(players)
else
chat("30 seconds left!")
wait(20)
chat("10 seconds left!")
wait(7)
chat("Only a FEW seconds left 0:")
wait(3)
for i, player in ipairs(game.Players:GetChildren()) do
if player.leaderstats.Level.Value ~= 0 then
player.Character.Health = 0
local boom = Instance.new("Explosion")
boom.Parent = player.HumanoidRootPart
boom.Position = player.HumanoidRootPart.Position
print("Killed")
end
end
end
end
end)
This is my code. I haven’t fully added the leaderboard part of it yet, but I have encountered a problem where the other players that don’t make it to the end don’t explode and die
Is that because your checking if they are not on level 0?
I fixed it. Don’t worry. Just need to add the leaderboard.