Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my script returning error "Position is not a valid member of Script?"

Asked by
Klamman 220 Moderation Voter
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So, I'm back again with another issue. My script is working fine

local activeNPCs = workspace.ActiveNPCs
spawns = game.Workspace.Spawns:GetChildren()

local function spawnNPC()
    local NPCs = game:GetService("ReplicatedStorage").AvailableNPCs:GetChildren()
    local randomNPC = NPCs[math.random(1,#NPCs)]
    randomNPC.Parent = game:GetService("ReplicatedStorage").UnavailableNPCs
    local newNPC = randomNPC:clone()
    newNPC.Parent = activeNPCs
    newNPC:MoveTo(spawnPos)
    local newForceField = Instance.new("ForceField",newNPC)
    game:GetService("Debris"):AddItem(newForceField, 10)
end

for i = 1, #spawns do
    chosenspawn = spawns[i]
    spawnPos = chosenspawn.Position
    spawnNPC()
    wait()
end

Oddly, though, it's giving me this error. Why is this? There is no problem in the functionality. This is my output.

20:21:50.024 - Auto-Saving... 20:21:52.230 - Position is not a valid member of Script 20:21:52.231 - Script 'ServerScriptService.SpawnNPCs', Line 17 20:21:52.231 - Stack End 20:22:24.397 - Auto-Saving...

Thanks!

1 answer

Log in to vote
1
Answered by
Acheo 230 Moderation Voter
8 years ago

Position is not a valid member of Script

You need to ensure that there is not a script inside of that model, otherwise get Children may be attempting to get the position of a script which is infact not possible. As for line 17, it lies under line 2.

Ad

Answer this question