I want to detect when ever a players' race position changes but i think i messed up somewhere

Server Script

local RacePositionFunction = Instance.new("RemoteFunction", storage)
RacePositionFunction.Name = "PositionEvent"

local function ChangePosImage(plr)
    local RaceStatistics = game.Workspace.Game.RaceStatistics
    RacePositionFunction.OnServerInvoke = ChangePosImage
end

Local Script

local RacePositionEvent = storage:WaitForChild("PositionEvent")

local function DisplayRacePosition(Pos,imge)
	
local RaceStatistics = game.Workspace.Game.RaceStatistics
local Positions = RaceStatistics.Positions

local Bleh = false

if RaceStatistics.Racing.Value == true then
	if Bleh == false then
		
		Bleh = true
		
		repeat
			for i,k in pairs(game.Players:GetPlayers()) do
				if k.Racing.Value == true then 	
					if k.Character:findFirstChild("UpperTorso") then
											
						local magnitude = (k.Character.UpperTorso.Position - game.Workspace.Game.TimingSystem.Sections:findFirstChild("Section"..k.Section.Value + 1).Position).magnitude
						
						Positions[k.Name].Value = magnitude
						
						local MyPos = 8
												
						for i,v in next, Positions:GetChildren() do
							if v.name ~= "NotUsed" then
							
								local temp = v.Name
								
								if game.Players[temp].Lap.Value < k.Lap.Value then
									MyPos = MyPos - 1
								elseif (game.Players[temp].Lap.Value == k.Lap.Value) and (game.Players[temp].Section.Value < k.Section.Value) then 
									MyPos = MyPos - 1
								elseif (game.Players[temp].Lap.Value == k.Lap.Value) and (game.Players[temp].Section.Value == k.Section.Value) and (v.Value > Positions[k.Name].Value) then 
									MyPos = MyPos - 1
								end
							end
						end 
								
						k.Position.Value = MyPos
						
						local Gui = k.PlayerGui:FindFirstChild("UI")
						
						local CapablePositions = 
						
						{
							[1]  = "asset",
							[2]  = "asset",
							[3]  = "asset",
							[4]  = "asset",
							[5]  = "asset",
							[6]  = "asset",
							[7]  = "asset",
							[8]  = "asset",
							[9]  = "asset",
							[10] = "asset",
						}						
						
						CapablePositions[MyPos] = 1 --dno how to use this yet
						
						
						if MyPos == 1 then
							k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543327"
						elseif MyPos == 2 then
							k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543295"
						elseif MyPos == 3 then
						    k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543256"
						elseif MyPos == 4 then
						    k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543238"
						elseif MyPos == 5 then
						    k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543224"
						elseif MyPos == 6 then
						    k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543196"
						elseif MyPos == 7 then
						    k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543181"
						elseif MyPos == 8 then
						    k.PlayerGui.UI.Positioning.Image = "http://www.roblox.com/asset/?id=73543122"
						end 
					end
				end
			end
						
		wait()
		
		until RaceStatistics.Racing.Value == false 
							
		Bleh = false
		
		end
	end
end
		
local RaceStatistics = game.Workspace.Game.RaceStatistics	
RaceStatistics.Racing.Changed:Connect(RacePositionEvent:InvokeServer())
warn("WORKING!!")			

Thanks for attempting :)

2 comments

0

the ChangePosImage function doesn't actually do anything

0

so shall i get rid of that bit?