Attempt To Index Nil with 'Position'

How do I fix this issue?

CODE:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local FireworkFireRemote = ReplicatedStorage:WaitForChild('Fire')

local Debris = game:GetService("Debris")

FireworkFireRemote.OnClientEvent:Connect(function(Start, Middle, Finish, FireworkLength, FireworkClone, ColorPoints, ExplosionDetail, OrbSizePoints)
	Debris:AddItem(Middle, 35)
	local function lerp(Part0, Part1, Time)
		return Part0 * (1-Time) + Part1 * Time
	end

	local function quad(p0,p1,p2,t)

		local l1 = lerp(p0, p1, t)
		local l2 = lerp(p1, p2, t)
		local quad = lerp(l1,l2, t)
		return quad
	end

	
	local function CreatePath()
		for i = 1,FireworkLength do
			local t = i/65
			
			local updated = quad(Start.Position, Middle.Position, Finish.Position, t)

			FireworkClone.Position = updated
			wait(.01)

			if i == FireworkLength then
				local Effects = FireworkClone.Attachment:WaitForChild("SparksRelease")
				local Launch = FireworkClone.Attachment:WaitForChild("Launch")

				Launch:Play()
				wait(.05)
				Effects.Color = ColorSequence.new(ColorPoints)
				
				local Sound1 = FireworkClone.Attachment:WaitForChild("Firework")
				Sound1:Play()
				Debris:AddItem(FireworkClone, 20)
				Effects:Emit(ExplosionDetail)
			end
		end
	end

	CreatePath()
end)
2 Likes

Is FireworkClone a model or part?

The FireworkClone: it is a part.

And this script is placed under StarterGUI.

One of your arguments is nil, which is producing this error. Try printing each argument on the client to see which one doesn’t exist, and check if you are firing the correct values to the remote.

I have printed every argument and it seems to work, other than this.

Assuming the code is not detecting updated as a Vector3 so you could try replacing FireworkClone.Position = updated with FireworkClone.Position = Vector3.new(updated)

Nope, it doesn’t work sadly. Its directing me to this part of the script.

local updated = quad(Start.Position, Middle.Position, Finish.Position, t)

To me this seems like you are experiencing a parameter issue in your code. You react to the FireworkFireRemote Event and you take multiple parameters even though the first parameter for RemoteEvents is always the PlayerInstance of the client that the LocalScript fired from.

As your script now tries to get the position of the player instance it errors as a player instance does not contain a position property.

Does this code work better? @AxeltAnt

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local FireworkFireRemote = ReplicatedStorage:WaitForChild('Fire')

local Debris = game:GetService("Debris")

FireworkFireRemote.OnClientEvent:Connect(function(player, Start, Middle, Finish, FireworkLength, FireworkClone, ColorPoints, ExplosionDetail, OrbSizePoints)
	Debris:AddItem(Middle, 35)
	local function lerp(Part0, Part1, Time)
		return Part0 * (1-Time) + Part1 * Time
	end

	local function quad(p0,p1,p2,t)

		local l1 = lerp(p0, p1, t)
		local l2 = lerp(p1, p2, t)
		local quad = lerp(l1,l2, t)
		return quad
	end

	
	local function CreatePath()
		for i = 1,FireworkLength do
			local t = i/65
			
			local updated = quad(Start.Position, Middle.Position, Finish.Position, t)

			FireworkClone.Position = updated
			wait(.01)

			if i == FireworkLength then
				local Effects = FireworkClone.Attachment:WaitForChild("SparksRelease")
				local Launch = FireworkClone.Attachment:WaitForChild("Launch")

				Launch:Play()
				wait(.05)
				Effects.Color = ColorSequence.new(ColorPoints)
				
				local Sound1 = FireworkClone.Attachment:WaitForChild("Firework")
				Sound1:Play()
				Debris:AddItem(FireworkClone, 20)
				Effects:Emit(ExplosionDetail)
			end
		end
	end

	CreatePath()
end)

Hmm. that’s a different error. It seems that “FireworkLength”, one of the variables that you pass when the event is fired, is nil. If you want me to help you it would be necessary to show me the LocalScript responsible for firing the event to see what variables you pass there.

1 Like

Where do you fire the Remote Event? I can’t seem to find it…

Hmm, I can’t really find an issue in this code. Could you print the FireworkLength please?

The fireworklength has a value after printing them. The start, middle, finish position have a value as well. I have no idea why is it nil.