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

Why accessory not valid and player wont teleport?

Asked by
TechModel 118
3 years ago
Edited 3 years ago

I have this teleport script that's disabled and the script is part scaled in an area. When it gets enabled, the players in the area gets teleported to a part "BackOut" and the issue I get is an error in the output "moveTo is not a valid Accessory ..."

local Teleport = "BackOut"
local Debounce = false
function Touch(hit)

    if not Debounce then

        Debounce = true

    local Pos = script.Parent.Parent:findFirstChild(Teleport)
        hit.Parent:moveTo(Pos.Position)
        wait(.5)
        Debounce = false
    end
end 

script.Parent.Touched:connect(Touch)

1 answer

Log in to vote
1
Answered by 3 years ago

Sometimes player's accessories will trigger the Touched event, you can avoid this error by doing...

if hit.Parent:IsA("BasePart") then -- Check if it is a part and not an accessory
    hit.Parent:PivotTo(Pos.Position) -- PivotTo is the better version of MoveTo
    Debouce = false
end
0
Using PivotTo, the output says unable to cast vector3 to CoordinateFrame TechModel 118 — 3y
0
My bad, it needs to be a CFrame, so hit.Parent:PivotTo(CFrame.new(Pos.Position)) climethestair 1663 — 3y
Ad

Answer this question