My script is not Finding a "Character"

So I am making a teleporter.

You hit one thing it takes you somewhere else.

But I am getting two really really werid errors.

local part = script.Parent

part.Touched:Connect(function(hit)
	local teleporter = script.Parent.Parent.Parent.Parent.Level2Lob.OverSpawn
	hit.Parent:FindFirstChild('Humanoid').Character.HumanoidRootPart.CFrame = teleporter.CFrame
end)

remove the character part in the Hit.Parent. The Hit.Parent is the Character.

Doing that makes this error pop up.

remove the :FindFirstChild("Humanoid") part too lol.

hit.Parent.HumanoidRootPart.CFrame = teleporter.CFrame
1 Like

In the script you assumed that the part will be always touched by players characters and this might cause issues. You can fix that:

local players = game:GetService("Players")
local part = script.Parent

part.Touched:Connect(function(hit)
	local potentialChar = players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model")) -- It's not nil if character touched the part. potenitalChar will always be nil or player's character
	if potentialChar then -- Check if character touched it
		-- Here potential character is definitely player's character. Do character scripting stuff here
	end
end)

you might want to consider checking is humanoid exists first and than execute the action.
The way you do it now you will get errors for each non character parts touching your teleporter.
And remember the humanoid is a child within the player character model like the rest of the parts such as HumanoidRootPart so you have to access them through it

local part = script.Parent
local teleporter = script.Parent.Parent.Parent.Parent.Level2Lob.OverSpawn

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        hit.parent.HumanoidRootPart.CFrame = teleporter.CFrame
    end
end)