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

Position is not a valid member of Model?

Asked by 6 years ago

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 
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. User#5423 17 — 6y
0
but its sometimes working! Can i get the new correct script? FrezeTagger 75 — 6y

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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 
0
Thanks! FrezeTagger 75 — 6y
Ad

Answer this question