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

Why accessory not valid and player wont teleport?

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

✓ Accepted answer

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

2 comments

0

Using PivotTo, the output says unable to cast vector3 to CoordinateFrame

0

My bad, it needs to be a CFrame, so hit.Parent:PivotTo(CFrame.new(Pos.Position))

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