Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index nil with Position?

Asked by
Maxis_s 97
4 years ago

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'
0
Quick note that I used this exact same line of code 2 hours ago and it worked perfectly fine Maxis_s 97 — 4y

4 answers

Log in to vote
0
Answered by
Mroczusek 111
4 years ago

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.

0
It's an ObjectValue instance: you can save the ".Value" property as a variable. Maxis_s 97 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

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. xMicro_Canary 37 — 4y
0
ohh CosmicIsGod 139 — 4y
0
ohh CosmicIsGod 139 — 4y
Log in to vote
0
Answered by 4 years ago

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.

Log in to vote
0
Answered by 4 years ago

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

Answer this question