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

Attempt to index nil with Position?

Script:

local Players = game.Players:GetPlayers()

local BodyVelocity = script.Parent.BodyVelocity

repeat
	wait()
	Players = game.Players:GetPlayers()
until #Players > 0

local Settings = script.Parent.Settings

local Aiming = script.Parent.Aiming
local Target = script.Parent.Target.Value

wait(Settings.AimTime.Value)

Aiming.Value = false
script.Parent.Anchored = false

script.Parent.BodyVelocity.Velocity = CFrame.new(-script.Parent.Position, -Target.Position).Position

Error:

Workspace.RockProjectile.Main:20: attempt to index nil with 'Position'

1 comment

0

Quick note that I used this exact same line of code 2 hours ago and it worked perfectly fine

4 answers

I'm pretty sure the issue here is that "Target" is a Value, though you didn't explain what Value in the Target object is.

1 comment

0

It's an ObjectValue instance: you can save the ".Value" property as a variable.

Target is a value, you have to first convert it to Vector3.

local Players = game.Players:GetPlayers()

local BodyVelocity = script.Parent.BodyVelocity

repeat
    wait()
    Players = game.Players:GetPlayers()
until #Players > 0

local Settings = script.Parent.Settings

local Aiming = script.Parent.Aiming
local Target = script.Parent.Target.Value

wait(Settings.AimTime.Value)

Aiming.Value = false
script.Parent.Anchored = false

script.Parent.BodyVelocity.Velocity = CFrame.new(-script.Parent.Position, -Vector3.new(game.Workspace[Target].Position)) 

Try this code. Edit: I understand better now try this.

3 comments

0

That's not the issue, as he stated it's an objectValue. Suppose ObjValue.Value = workspace.Part. Running ObjValue.Value.Position is perfectly valid.

0

ohh

0

ohh

Many people here are mistaking that "Position" doesn't exist. If you read it carefully, you can see that it says that you're taking "position" from something that doesn't exist.

What people think is happening:

local tab = {}
print(tab.Position) -- position doesn't exist

What is actually happening:

local tab = nil
print(tab.Position) -- you're getting position from a non existant value, or nil

Therefore

-script.Parent.Position
-Target.Position

One of these are nil. Either script.Parent doesn't exist (highly unlikely) Or target.Value hasn't been assigned to yet.

Chances are, it's the latter.

Either Target.Value is nil or Target.Value is an object without a Position value.

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