hello, I made this script for my time trial game and everything is working to a dime, except for the problem of players being invisible if they join after the players rootpart is moved. What is the solution to this problem? thank you again I am new to scripting so any feedback is helpful to streamline my code
edit: the problems occurs when one player is teleported via the rootpart, and when a second player joins the game they are unable to see the player that was teleported (this player joined before)
local Players = game.Players
local raceStart = game.workspace.raceStart
local raceEnd = game.workspace.raceEnd
local rep = game:GetService("ReplicatedStorage")
rep.beginRace.OnServerEvent:Connect(function(player)
player.gameStatus.Value = "started"
player.Character.HumanoidRootPart.Position = raceStart.Position
player.leaderstats:WaitForChild("Current Time").Value = 0
wait(4)
local startTime = coroutine.wrap(function()
repeat
player.leaderstats:WaitForChild("Current Time").Value = player.leaderstats:WaitForChild("Current Time").Value + 1
wait(1)
until player.gameStatus.Value == "ended"
end)
startTime()
end)
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local currentTime = Instance.new("IntValue")
currentTime.Name = "Current Time"
currentTime.Parent = leaderstats
local gameStatus = Instance.new("StringValue")
gameStatus.Name = "gameStatus"
gameStatus.Parent = player
end)
raceEnd.Touched:Connect(function(bodyPart)
local char = bodyPart.Parent
char.HumanoidRootPart.Position = game.Workspace.SpawnLocation.Position
local player = Players:GetPlayerFromCharacter(char)
player.gameStatus.Value = "ended"
rep.endRace:FireClient(player)
end)