Why can't this function?

Hello Roblox Developers!
My script finds every Jeep in the Raceway folder and finds Configurations > Speed and increases the value of Speed by 25.
However, it doesn’t work, and I can’t find a solution!
Script:

rep.FasterCars.OnServerEvent:Connect(function(player)
	for i, v in pairs(game.Workspace.Raceway.Jeep:GetChildren()) do
		if v.Name == "Configurations" then
			local iv = v:GetChildren()
			if iv.Name == "Speed" then
				iv.Value += 25
			end
		end
	end
end)

Can someone please help me? Thanks!

???

iv is a table, not an instance and so you’re just indexing a regular table

1 Like

Thats a table, you have to use for pairs loop again.

rep.FasterCars.OnServerEvent:Connect(function(player)
	for i, v in pairs(game.Workspace.Raceway.Jeep:GetChildren()) do
		if v.Name == "Configurations" then
			local iv = v:GetChildren()
			for index,value in pairs(iv) do
                if value.Name == "Speed" then
				   value.Value += 25
			    end
            end
		end
	end
end)
2 Likes

i tried it and it didnt work though

same result though, nothing changed

Any errors in the output, is the event firing?

1 Like

no errors, and the event is firing

You’re looping through a single Jeep’s children in the outer loop

1 Like

i dont get it, whats that supposed to mean?

Maybe your speed is in other parent that :GetChildren isnt reaching to?
Use Instance:GetDescendants() to get each item in a model or a folder.

rep.FasterCars.OnServerEvent:Connect(function(player)
	for i, v in pairs(game.Workspace.Raceway.Jeep:GetDescendants()) do
        if v.Name == "Speed" then
		   v.Value += 25
	    end
	end
end)
1 Like

This line is saying “loop through every child Raceway.Jeep”

I think what you want to say is “loop through every child of Raceway. if it’s a jeep, …”

2 Likes

configurations is inside jeep, and speed is inside configurations!

and no it still doesnt work for some reason

How many jeeps there are in Raceway folder?

2 Likes

Thank you, your post worked and synitx too so i combined both your ideas and it worked! I have to give the credit to you though because thats the one that actually sparked the main problem.