Ok I'm trying to animate a brick into a teleporter where it will go up if touched but when I teleport it does not go down all the way, it's saying this error: attempt to index field 'Parent' (a nil value)
How can I fix this?
gui.teleport.MouseButton1Click:connect(function() if not selloc then return end if(selloc.Group.Value ~= 0)then local infoassoc = groupserv:GetGroupInfoAsync(selloc.Group.Value) if(infoassoc and (not me:IsInGroup(selloc.Group.Value)))then gui.cardview.grouperror.Text = "Teleport Failed: You're not in the group \""..infoassoc.Name.."\"" gui.cardview.grouperror.Visible = true return end end local teleport = Instance.new("IntValue", me) teleport.Name = "JustTeleported" game:GetService("Debris"):AddItem(teleport, 5) gui.Visible = false wait(2) porter.User.Value = nil me.Character:MoveTo(selloc.Porter.Position) me.Character.Humanoid.WalkSpeed = 16 for i = 1,10 do local Part = game.workspace['Instant Teleport'].Union Part.CFrame = Part.CFrame * CFrame.new(0,-1,0) wait(1) script.Parent:Destroy() -- Error occurs here end end)
You've put script.Parent:Destroy()
in a for loop that repeats 10 times. My guess is that you want it to be:
--rest of script here, up to and including the line: me.Character.Humanoid.WalkSpeed = 16 local Part = game.workspace['Instant Teleport'].Union for i = 1, 10 do Part.CFrame = Part.CFrame * CFrame.new(0,-1,0) wait(1) end script.Parent:Destroy() end)
You can minimize errors like this by using proper indentation (there should be an extra indent after the 'for'). If you ever see two "ends" in a row at the same indent level, you've missed indenting a block.
The error is occurring because script.Parent:Destroy()
destroys the script (since script
is a child of script.Parent), setting its .Parent property to nil. Attempting to call anything on a nil value causes the type of error you encountered.