Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[CLOSED] MoveTo is not a valid member of Accessory Help?

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)

2 comments

1

Ohh, that's what happen when you hat touched the Brick instead of Character parts

1

Hat > Handle, This is what happened hit == Handle, hit.Parent == Hat

2 answers

✓ Accepted answer

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 :)

2 comments

0

Sorry But I tried his first, and accepted it, yours works as well, thank you for your time !

0

My answer is better as it will work even if it's not the Hit's Parent or Hit's Parent's Parent

This discussion is preserved as it was. New answers, comments, and votes are closed.