So I have a teleporter in my game that teleports Players around the map but if a Npc goes in the teleporter I get this error
TeleportFolder.Path6to1Reciver.Touched:Connect(function(hit) -- hit is the argument passed through, can be named anything
if hit.Parent:FindFirstChild("Humanoid") then
local PlayerService = game:GetService("Players")
local Player = PlayerService:GetPlayerFromCharacter(hit.Parent)
local Char = Player.Character or Player.CharacterAdded:Wait()
local HRP = Char:WaitForChild("HumanoidRootPart")
Vibration:FireClient(Player)
wait(0.2)
HRP.CFrame = EndTeleportCFrames.Island6.CFrame
Char:WaitForChild("TELEPORTED").Value = true
Vibration:FireClient(Player)
Player.PlayerGui.IslandText.Island6.Visible = true
wait(2)
Player.PlayerGui.IslandText.Island6.Visible = false
Char:WaitForChild("TELEPORTED").Value = false
end
end)
TeleportFolder.Path6to1Reciver.Touched:Connect(function(hit) -- hit is the argument passed through, can be named anything
if hit.Parent:FindFirstChild("Humanoid") then
local PlayerService = game:GetService("Players")
local Player = PlayerService:GetPlayerFromCharacter(hit.Parent)
local HRP = hit.Parent:FindFirstChild("HumanoidRootPart")
if Player then
local Char = Player.Character or Player.CharacterAdded:Wait()
Vibration:FireClient(Player)
wait(0.2)
end
HRP.CFrame = EndTeleportCFrames.Island6.CFrame
hit.Parent:WaitForChild("TELEPORTED").Value = true
if Player then
Vibration:FireClient(Player)
Player.PlayerGui.IslandText.Island6.Visible = true
wait(2)
Player.PlayerGui.IslandText.Island6.Visible = false
end
hit.Parent:WaitForChild("TELEPORTED").Value = false
end
end)
If Teleported isn’t a thing in your NPC’s, just put it in the if statements as well
Then only do th ecode if a player is found then, use this
TeleportFolder.Path6to1Reciver.Touched:Connect(function(hit) -- hit is the argument passed through, can be named anything
if hit.Parent:FindFirstChild("Humanoid") then
local PlayerService = game:GetService("Players")
local Player = PlayerService:GetPlayerFromCharacter(hit.Parent)
if not Player then return end
local Char = Player.Character or Player.CharacterAdded:Wait()
local HRP = Char:WaitForChild("HumanoidRootPart")
Vibration:FireClient(Player)
wait(0.2)
HRP.CFrame = EndTeleportCFrames.Island6.CFrame
Char:WaitForChild("TELEPORTED").Value = true
Vibration:FireClient(Player)
Player.PlayerGui.IslandText.Island6.Visible = true
wait(2)
Player.PlayerGui.IslandText.Island6.Visible = false
Char:WaitForChild("TELEPORTED").Value = false
end
end)