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

Attempt to index nil with 'Position' fix?

Hello and thank you for viewing this. I am making a tycoon and I'm currently working on a feature that randomizes ores around the map. (the game is part simulator part tycoon) However, I've run into a problem. Apparently Roblox thinks that Position (or its value) is nil. But it isn't. Here's my code, the error occurs on Line 13:

function frc(model)
	local children = model:GetChildren()
	local child = children[math.random(1, #children)]
	return child
end

local x = workspace.Blocks:GetChildren()
wait(.1)
-- Make all ores random
for i = 1, #x do
	local v = x[i]
	if v.Name == 'Ore' then
		local p = x.Medium.Position
		local r = x.Medium.Orientation
		local c = frc(game.ReplicatedStorage.DecorParts1):Clone()
		c.Parent = v
		c.Position = p
		c.Orientation = r
	elseif v.Name == 'Ore+' then
		local p = x.Medium.Position
		local r = x.Medium.Orientation
		local c = frc(game.ReplicatedStorage.DecorParts2):Clone()
		c.Parent = v
		c.Position = p
		c.Orientation = r
	end
end

If you know any way to help, please tell me! Thanks again for taking your time to view my problem.

1 answer

✓ Accepted answer

I believe you meant to do v.Medium.Position It appears that x is an array

2 comments

0

Yeah... Thanks for the help!

0

No problem!

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