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

I keep getting "MoveTo is not a vaild member of Accessory"?

Asked by 3 years ago
Edited 3 years ago

Below is the code I used to teleport my players when they step on a block, it used to work wonders! But after some time it stopped working, I looked in the developer console and what I saw is that my clothing is messing the code up? What's supposed to happen is just tp the players but now it does nothing and just spits this error out. I just can't figure out what to do from here.

Some more helpful info: This happens in both Roblox Studio Play Test and just playing with the normal roblox client. I use a normal script not a local script.

local Teleport = "te7"
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 answers

Log in to vote
0
Answered by 3 years ago

Howdy!

What I believe is happening is that the .Touched. function is picking up Accessories on your character. These don't have a :MoveTo() function and are thus throwing an error. So, you need to probably tell your script to only run under circumstances where the item touching can be moved.

I'd replace your Line 3 with what I have below.

if not script.Parent.Locked and not script.Parent,Parent:FindFirstChild(Teleport).Locked and hit.Parent:IsA("Model") then

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

0
hit.Parent refers to the Accessory itself. DeceptiveCaster 3761 — 3y
0
I have a question though, how come this problem didn't happen before? I've had these accessories equiped way before this game was made too. DocGooseYT 110 — 3y
0
It could be possible that the part simply didn't pick those parts up and (if they did), they eventually got through your accessories and touched skin. TaxesArentAwesome 514 — 3y
0
Ah okay, makes sense. DocGooseYT 110 — 3y
View all comments (8 more)
0
I put your code in but now I'm getting errors saying it expected something else and not "then". DocGooseYT 110 — 3y
0
Never mind, I fixed it by replacing the comma with a dot. DocGooseYT 110 — 3y
0
Sorry, your last comment didn't load in. Hit me up again if you get any errors. TaxesArentAwesome 514 — 3y
0
Alright, so it works but for some reason now I keep getting teleported and I can't get out of the loop. The previous code I used fixed this and I did the same thing with your code except it isn't working. DocGooseYT 110 — 3y
0
When your replaced your code, did you remove the `script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true` part? You can readd that, if you did. TaxesArentAwesome 514 — 3y
0
yeah because you told me to replace line 3. But I'll readd it right now. DocGooseYT 110 — 3y
0
Yeah, I didn't notice that it was in the line. My fault. Readd it and tell me if your issues are resolved. TaxesArentAwesome 514 — 3y
0
Yup all my issues are resolved! Thank you very much! DocGooseYT 110 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Accessories contain a Handle part that your function is likely detecting. If, and only if, the parent of the BasePart is an Accessory, get that Accessory's Parent and verify that it is a player's character using GetPlayerFromCharacter().

Example:

-- Let's suppose a player is wearing a Shaggy. Hair items are Accessories by technicality, therefore they contain a Handle. We need to verify that this is indeed an Accessory's Handle.

function onTouched(hit)
    if hit:FindFirstAncestorWhichIsA("Model") then -- Verify that we have a model.
        local m = hit:FindFirstAncestorWhichIsA("Model")
        if game.Players:GetPlayerFromCharacter(m) then -- Verify that it is a player's Character.
            -- Other code.
        end
    end
end
0
Thank you, this example seems very helpful. Since I'm a beginner at scripting, you pointing out what the code does really helps out. I'll first try the other person's solution though if it doesn't work I'll do this. DocGooseYT 110 — 3y

Answer this question