Player is invisible after teleporting

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)
1 Like

I have had similar issues with characters positions being scrambled when teleporting them by changing their position. This probably wont help but try using the :SetPrimaryPartCFrame() function instead of setting their HRP position

I believe you should be using .CFrame instead of .Position. @SPR1NG3R

that should fix your issue.

char.HumanoidRootPart.CFrame= game.Workspace.SpawnLocation.CFrame+Vector3.new(0,3,0)

the vector 3 is just incase your spawn point is in the ground, gives the player’s cframe a sort of elevation and prevents falling under map or getting stuck in ground

3 Likes

Thank you! I’ve been having this problem for ages and this is the only one that i could find that actually fixes it.