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

Position is not a valid member of Model?

Hello, I am making an Minigame. I made an script. sometimes its not working but sometimes its working! Here is the script! I think i am correct but why its not working sometimes?

maps = game.ServerStorage.Maps:GetChildren()
map = maps[math.random(1, #maps)]
wait(3)
map:Clone().Parent = game.Workspace
game.Workspace.Message.Value = "The Game is Starting!"
wait(3)
		
	
for i, Player in pairs(game.Players:GetPlayers()) do
	print(Player.Name)
	if Player.Character then
		Player.Character:MoveTo(workspace:FindFirstChild(map.Name).Spawns:GetChildren()[math.random(1, #workspace:FindFirstChild(map.Name).Spawns:GetChildren())].Position)
	end
end	

2 comments

0

A model is not a basepart and has not position. You can set the PrimaryPart which will use the given part as the Models CFrame.

0

but its sometimes working! Can i get the new correct script?

1 answer

✓ Accepted answer

Apparently one of the children of workspace(map.Name).Spawns is a Model, and other are Parts.

You should browse through all of them and set a PrimaryPart for each one to the part you want the players to spawn on.

maps = game.ServerStorage.Maps:GetChildren()
map = maps[math.random(1, #maps)]
wait(3)
map:Clone().Parent = game.Workspace
game.Workspace.Message.Value = "The Game is Starting!"
wait(3)


for i, Player in pairs(game.Players:GetPlayers()) do
    print(Player.Name)
    if Player.Character then
        local spawns = workspace:FindFirstChild(map.Name).Spawns:GetChildren()
        local randomSpawn = spawns[math.random(1, #spawns)
        local targetPos = randomSpawn:IsA("BasePart") and randomSpawn.Position or randomSpawn.ClassName == "Model" and (randomSpawn.PrimaryPart and randomSpawn.PrimaryPart.Position or randomSpawn:FindFirstChildOfClass("Part").Position)
        Player.Character:MoveTo(targetPos)
    end
end 

1 comment

0

Thanks!

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