Invalid 'for' limit (number expected, got nil)

How to I fix this error? I tried many different ways and it seem its getting worse.

This is the script:

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)
1 Like

1 Like

Thanks for this information!
errro3

1 Like

can u paste again your script?

2 Likes
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, 10, 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

Can you show the server script firing the remoteevent? Also, when you fire a remoteevent from the server you write the player you want to fire to with all the other arguments aswell, but this doesn’t mean that the player will be sent over as an argument as you’ve done here:

FireworkFireRemote.OnClientEvent:Connect(function(player, Start, Middle, Finish, FireworkLength, FireworkClone, ColorPoints, ExplosionDetail, OrbSizePoints)

This is the script that is responsible in firing the event.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local FireworkFireRemote = ReplicatedStorage:WaitForChild('Fire')

local Debris = game:GetService("Debris")

local FireworksModule = {}

function FireworksModule:CreateFireworkParams(fireworks)
	--/Variables
	local Start, Finish = fireworks:WaitForChild("Start"), fireworks:WaitForChild("Finish")
	
	Start.Transparency = 1
	Finish.Transparency = 1
	
	local Firework = fireworks.Parent:WaitForChild("Firework")
	
	local Parent1 = fireworks.Parent
	local DebrisFolder = Parent1:WaitForChild("FireworkDebris")


	local Lighting = game:GetService("Lighting")

	---/Attributes
	local FireworkLength = script.Parent:GetAttribute("FireworkLength")
	local ExplosionDetail = script.Parent:GetAttribute("ExplosionDetail")
	
	local TrailOffsetYMin = script.Parent:GetAttribute("TrajectoryOffsetYMin")
	local TrailOffsetYMax = script.Parent:GetAttribute("TrajectoryOffsetYMax")
	
	local TrailOffsetXZMin = script.Parent:GetAttribute("TrajectoryOffsetXZMin")
	local TrailOffsetXZMax = script.Parent:GetAttribute("TrajectoryOffsetXZMax")
	
	--/Colorization
	local Color1 = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
	local Color2 = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))

	local ColorPoints = {
		ColorSequenceKeypoint.new(0, Color1),
		ColorSequenceKeypoint.new(1, Color2)
	}
	
	
	local Middle = Instance.new("Part")
	Middle.Anchored = true
	Middle.Transparency = 1
	Middle.Parent = DebrisFolder

	

	local FireworkClone = Firework:Clone()
	FireworkClone.Anchored = true
	FireworkClone.Parent = DebrisFolder

	local Trail = FireworkClone:WaitForChild("Trail")
	Trail.Color = ColorSequence.new(ColorPoints)
	FireworkClone:WaitForChild("Attachment"):WaitForChild("Shine").Enabled = true
	FireworkClone:WaitForChild("Attachment"):WaitForChild("Shine").Color = ColorSequence.new(ColorPoints)
	local Dst = math.abs((Finish.Position - Start.Position).Magnitude)
	Middle.CFrame = CFrame.new(Start.Position, Finish.Position) * CFrame.new(0, 0, -Dst/2) 
	Middle.Position = Middle.Position + Vector3.new(math.random(TrailOffsetXZMin, TrailOffsetXZMax),math.random(TrailOffsetYMin, TrailOffsetYMax),math.random(TrailOffsetXZMin, TrailOffsetXZMax))
	
	--/ Let client do the rest to save space on server
	FireworkFireRemote:FireAllClients(Start, Middle, Finish, FireworkLength, FireworkClone, ColorPoints, ExplosionDetail)
end

return FireworksModule

I think the error is about the “Increment” Value, are you sure FireworkLenght is not nil?

1 Like

As suspected, one of the problems is the fact u take player as an argument, which messes up what variable stores what information. Just use this instead:

FireworkFireRemote.OnClientEvent:Connect(function(Start, Middle, Finish, FireworkLength, FireworkClone, ColorPoints, ExplosionDetail, OrbSizePoints)

Also, have you tried print(FireworkLength) to find the issue?

1 Like

Yep! It does have a value.
fireworklength

However, this time this error pops out.
firework22

FireworkClone is nil, can’t see why though. Try printing Firework and FireworkClone in the regular script, see if u can find the issue there.

The FireworkClone is nil after printing. Both are Nil.

1 Like

You used WaitForChild for the variables which literally can’t be nil. It confuses me why they are though. Like this line, IT CANT BE NIL BUT IT IS: fireworks.Parent:WaitForChild(“Firework”).

Are there any more outputs like “Infinite possible yield” or something in the console?

1 Like

Nope, thats the only error I have gotten.

1 Like

Nope, it is not nil. There is a value after printing them.

1 Like

It used to be nil, but it’s fixed and now the problem is that the Firework is nil.

1 Like

Is it Archivable? Because if it isn’t it can’t be cloned.

2 Likes

Wait, you turned off Archivable? Also if the original variable fireworks.Parent:WaitForChild("Firework") is nil, then Archivable can’t be the issue, right?

No it has to be on so you can clone it.

Wait oops. Sorry read it wrongly. Yep, the error attempt to index with ‘position’ its still here. This is confusing, I am not sure what have gone wrong.

1 Like