The first problem:
The touched event fired because of touching an Accessory and in that case the Character would be Hit.Parent.Parent, I like to use Nevermore's GetPlayerFromCharacter to prevent this issue, It can be found here what it does different is that it will also check if an Ancestor of Hit is the Character's Model
The second problem:
MoveTo is a method of the Humanoid and not the Character model, you can find the Humanoid in the Character like shown below, you would then do :MoveTo() on the Humanoid
The solution(Using Nevermore):
local LoadCustomLibrary = require(ReplicatedStorage:WaitForChild("Nevermore"))
local CharacterUtil = LoadCustomLibrary("CharacterUtil")
local Player = CharacterUtil.getPlayerFromCharacter(InsertHitHere)
local Character = Player.Character
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
The solution(Without Nevermore):
We check if the Hit is a Descendant of any of the Players
function getPlayerFromCharacter(descendant)
for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
if descendant:IsDescendantOf(Player.Character) then
return Player
end
end
end
local Player = getPlayerFromCharacter(InsertHitHere)
local Character = Player.Character
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
Don't forget to mark my answer as the solution and upvote it if it answered your question :)
2 comments
Ohh, that's what happen when you hat touched the Brick instead of Character parts
Hat > Handle, This is what happened hit == Handle, hit.Parent == Hat