I have been trying to get this script to work, but so far it can only tell when another player is close to you, whenever i add the lines of code that take into account the amount of laps each player has, it doesnt work… this is the script so far
me = game.Players.LocalPlayer
dist = 200
Flag = Instance.new("ScreenGui",me.PlayerGui)
Flag.Name = "Blue Flag"
bg = Instance.new("ImageLabel",Flag)
bg.Size = UDim2.new(0,200,0,200)
bg.Position = UDim2.new(0.15, 0, 0.8, -100)
bg.Image = "http://www.roblox.com/asset/?id=397459039"
bg.BackgroundTransparency = 1
Flag.Enabled = false
laps = me.leaderstats.laps
while true do
wait()
for _,v in pairs(game.Players:GetPlayers()) do
if v.Name ~= me.Name then
if v.Character then
local tor = v.Character:findFirstChild("Head")
local lapsCompleted = v.leaderstats.laps.Value
if tor then
local di = (me.Character.Head.Position - tor.Position).magnitude
if di < dist then
if laps.Value < lapsCompleted then
Flag.Enabled = true
end
end
if dist < di then
Flag.Enabled = false
end
end
end
end
end
end
the specific line that isnt set up properly, or well the specific lines i should day, is everything that mentions laps, these lines:
local lapsCompleted = v.leaderstats.laps.Value
if laps.Value < lapsCompleted then Flag.Enabled = true
if i delete that and the if, and move the flag.enabled = true under the distance if, it shows the gui when another player is behind you regardless of how many laps the other person has
local goalZone = Vector3.new(0,0,5)
local max = 15
local HRP = player.Character.HumanoidRootPart
while wait(1) do
if HRP.Position.Z > goalZone.Z and HRP.Position < max then
print("You reached the GoalZone! Flag.enabled == true")
else
print("You dont reached the GoalZone! Flag.enabled == false ")
end
end
i can’t leave the other player out, then the script would be useless… pretty much what im trying to do is give a signal to a player that tells him another player with more laps is approaching him…
like i previously said, so far i have only managed to make a script that shows a signal when another player is close without taking laps into consideration, what i need help with is making it work only when the player that is approaching has more laps
local Racestatus = true --if the Race is running
local Radius = 20
local LocalPlayer = nil
local NumberOfPlayers = 0
for index, player in pairs(game.Players.GetPlayers()) do
if player ~= nil then
NumberOfPlayers = NumberOfPlayers + 1
end
end
game.Players.PlayerAdded:Connect(function(player)
LocalPlayer = player
end)
while NumberOfPlayers > 0 and Racesatus do
spawn(function()
local AllPlayers = game.players:GetPlayers()
for index, player in ipairs(AllPlayers) do
local OtherPlayer = AllPlayers[index + 1]
if not player.Name == LocalPlayer then
print("Player "..player.Name.."is "..player:DistanceFromCharacter(OtherPlayer.Head.Position).."from"..OtherPlayer.Name.." away")
end
if player:DistanceFromCharacter(OtherPlayer.Head.Position) < Radius and OtherPlayer.leaderstats.laps.Value > LocalPlayer.leaderstats.laps.Value then
print("Player "..OtherPlayer.Name.." comes with "..OtherPlayer.leaderstats.laps.Value.." laps more than you")
end
end
end)
end
If done from a LocalScript, LocalPlayer is implicit. The first line is not necessary and it will infact register the LocalPlayer variable as other players when they join, so you should never do this.
game.players will throw an error because players is not a valid member of the DataModel. Use Players or game:GetService(“Players”) (canonical way to fetch a service).
GetPlayers generates an array; use ipairs to iterate through it. You should also not assume truthy values in your code (OtherPlayer is looked up at index++ which can be nil especially for the last iterated element of the array).
Thx, i dont tested my code. Ok i will edit it. It is from a ServerScript. I write Players and not players.
I want to read the website in the in pairs and ipairs (and key, I read it a long time ago but can’t find it again)
does that count as spam?.. i mean the first post is different from the other two and each post is separated by atleast a week, its not like im posting this every hour… i didnt get help so i decided to try again after a week… if it is spam then im sorry, i didnt know and i wont do that again
alright, just tried it and it isn’t working… first i just pasted the script in, fixed a grammar issue (line 13), placed it into the seats of two cars and published the game… i brought in a friend, he did a few laps more than me and when i checked the dev console nothing was printed… afterwards i decided to add all the lines of code that show the blue flag gui to see if that would change something, pasted the new script into the two car seats and tried again, same result, no gui and no printed message
local Racestatus = true --if the Race is running then it is true
local Radius = 20
local LocalPlayer = nil
local NumberOfPlayers = 0
for index, player in pairs(game.Players.GetPlayers()) do
if player ~= nil then
NumberOfPlayers = NumberOfPlayers + 1
end
end
game.Players.PlayerAdded:Connect(function(player)
LocalPlayer = player
end)
while Racestatus == true do
wait(2)
local AllPlayers = game.players:GetPlayers()
local OtherPlayer = nil
for index, player in ipairs(AllPlayers) do
if AllPLayers[player + 1] ~= nil then
OtherPlayer = AllPlayers[player + 1]
print(AllPlayers[player + 1].Name)--if this print something, then let me know, else here is a error
else
OtherPlayer = AllPlayers[player - 1]
print(AllPlayers[player - 1].Name)
end
if not player.Name == LocalPlayer then
print("Player "..player.Name.."is "..player:DistanceFromCharacter(OtherPlayer.Head.Position).."from"..OtherPlayer.Name.." away")
end
if player:DistanceFromCharacter(OtherPlayer.Head.Position) < Radius and OtherPlayer.leaderstats.laps.Value > LocalPlayer.leaderstats.laps.Value then
print("Here its WORK!!! Epic LOL.")
print("Player "..OtherPlayer.Name.." comes with "..OtherPlayer.leaderstats.laps.Value.." laps more than you")
end
end
end