Player name is not valid member bug

I find a bug that after they teleport you there would be an error which is this.

Untitled

Script teleporter :

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		wait(0.1)
		game:GetService("TeleportService"):Teleport(script.Parent.Parent.id.Value, game.Players[hit.Parent.Name])
	end
end)

Use a local script. I’m sure that’ll work.

1 Like
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		game:GetService("TeleportService"):Teleport(script.Parent.Parent.id.Value, Player)
	end
end)

Use FindFirstChild instead of the [] like this:

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		wait(0.1)
		game:GetService("TeleportService"):Teleport(script.Parent.Parent.id.Value, game.Players:FindFirstChild(hit.Parent.Name))
	end
end)