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