So I get this error :
MoveTo is not a valid member of Accessory
Please help!
local Teleport = "JohnTP3" function Touch (hit) if script.Parent.Locked == false and script.Parent.Parent : FindFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:FindFirstChild(Teleport).Locked=true local Pos = script.Parent.Parent:FindFirstChild(Teleport) hit.parent:MoveTo(Pos.Position) wait(1)script.Parent.Locked = false script.Parent.Parent:FindFirstChild(Teleport).Locked = false end end script.Parent.Touched:connect(Touch)
The new IF
is to check if It's the Character Body parts touched the Part, You can also detect if the hit is accessory or Tools, or you can just detect Humanoid of the part :> really up to you
local Teleport = "JohnTP3" function Touch (hit) if script.Parent.Locked == false and script.Parent.Parent : FindFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:FindFirstChild(Teleport).Locked=true local Pos = script.Parent.Parent:FindFirstChild(Teleport) local char = hit.Parent if hit.Parent:FindFirstChild("Humanoid") == nil then char = hit.Parent.Parent end char:MoveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:FindFirstChild(Teleport).Locked = false end end script.Parent.Touched:Connect(Touch)
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 :)