My script to relocate player isnt working?

I also find that it will connect a function every time and also won’t position on respawn. This will be a waste of memory, so here’s a fix:

local connection

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if connection then connection:Disconnect() end
		connection = character:WaitForChild("Humanoid").Died:Connect(function()
			print(player.Name .. " has died!")
		end)
		Player.Character:MoveTo(part.Position + Vector3.new(0, 3, 0))
	end)
end)
1 Like

Instead of using

if (isUsingVR) then
		hum.Died:Connect(function()
			wait(3)
				char.Parent = workspace.Players.VRPlayer

use this instead:

if (isUsingVR) then
		player.CharacterAdded:Connect(function(newchar)
			task.wait(3) --personally I would not use a wait here, but I added it anyway.
				newchar.Parent = workspace.Players.VRPlayer

This will give you the respawned character, and should function the same, although it will also run when you first spawn into the game. The other scripts seem to be unnecessary bloated with useless code.

If player seated, MoveTo may not working.

1 Like

My script works the same way. The “useless code” you say is actually the rest of the script that I worked off of.

your script is very clearly different.

That is because it actually moves the character as well. This is to make it ACTUALLY respawn in the intended spot.

1 Like

when i changed the code i get this error

ServerScriptService.KeepPlayersInFolder:2: attempt to index nil with ‘WaitForChild’

Ah. I forgot to move that into the CharacterAdded:

game.Players.PlayerAdded:Connect(function(player)
	local userInputService = game:GetService("UserInputService")
	local isUsingVR = userInputService.VREnabled
	if (isUsingVR) then
		player.CharacterAdded:Connect(function(char)
			local hum = char:WaitForChild("Humanoid") --idk if this is requred for VR ppl
			char.Parent = workspace.Players.VRPlayer
			char:MoveTo(workspace.VRPlayerSpawn.Position + Vector3.new(0, 4, 0))
			for childIndex, child in pairs(char:GetChildren()) do
				if child:IsA("BasePart") and child.Name ~= "Head" and child.Name ~= "UpperTorso" then

					child:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
						child.Transparency = 1
					end)

					child.Transparency = 1

				end
			end
		end)
	else
		player.CharacterAdded:Connect(function(char)
			local hum = char:WaitForChild("Humanoid")
			char.Parent = workspace.Players.NonVRPlayer
			char:MoveTo(workspace.VRPlayerSpawn.Position + Vector3.new(0, 4, 0))
		end)
	end
1 Like

Thanks for fixing it up. I just grabbed it from one of my games so it probably wasn’t optimised for this

1 Like

If the player is dead they can’t be seated

2 Likes

Exactly. I don’t know why seating would become an issue when a player can’t sit when they’re dead. :joy:

1 Like

…Sorry for that.
Also, here is documentation.
https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAdded