#attempted to index nil with position on something clearly defined

15 messages · Page 1 of 1 (latest)

nimble tendon
#

i am really confused how its indexing with a nil?

#

Size = 25
script.Parent.Size = Vector3.new(math.random(1,10) / Size,math.random(1,10) / Size,math.random(1,10) / Size)
while true do
wait()
if (script.Parent.Position - game.Workspace.CameraPos.Position).Magnitude > 512 then
wait()
script.Parent:Destroy()
end
if (script.Parent.Position - game.Workspace.CameraPos.Position).Magnitude < 50 then
wait()
script.Parent:Destroy()
end
end

#

this is the code

#

Workspace.Stars.Star.Script:9: attempt to index nil with 'Position'

#

it litarly says index nil with a script.Parent

night salmon
#

you shure that CameraPos isnt nil?

#

the Player camera Would be
workspace.CurrentCamera.CFrame.Position

#
Size = 25
local CamPart = game.Workspace.CameraPos


script.Parent.Size = Vector3.new(math.random(1,10) / Size,math.random(1,10) / Size,math.random(1,10) / Size)

while script.Parent and wait() do
    local dis = (script.Parent.Position - CamPart.Position).Magnitude

    if dis > 512 or dis < 50 then
        script.Parent:Destroy()
    end
end
edgy portal
nimble tendon
#

camerapos is identified

#

i some how fixed the code

#

script.Paernt:Destroy() destroys the parent

#

but doesnt stop the script

#

i fixed it by replacing script.parent:destroy() with game:GetService("Debris"):AddItem(script.Parent,0)

#

but it works with no errors now 😄