Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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)
1
Ohh, that's what happen when you hat touched the Brick instead of Character parts User#17685 0 — 4y
1
Hat > Handle, This is what happened hit == Handle, hit.Parent == Hat User#17685 0 — 4y

2 answers

Log in to vote
-2
Answered by 4 years ago

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)

Ad
Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago
Edited 4 years ago

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

0
Sorry But I tried his first, and accepted it, yours works as well, thank you for your time ! ItsBasicallyDenis -3 — 4y
0
My answer is better as it will work even if it's not the Hit's Parent or Hit's Parent's Parent Filipalla 504 — 4y

Answer this question