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' fix?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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

0
Yeah... Thanks for the help! QuantumPlasmic 84 — 4y
0
No problem! MalfestLuxor 35 — 4y
Ad

Answer this question