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

Zombie Spawner broke? Output error

Asked by 8 years ago

Sorry about reposting, I have a new issue with it, an output error. Again, simple script just I see an output error. The error is: 12:42:13.104 - Position is not a valid member of Model

So whats this mean? Here is the code:

local z = game.ReplicatedStorage.Zombie
local zc = z:Clone()
local fm = game.Workspace:FindFirstChild("Map")
local fs = fm:GetChildren("ZSpawn")

while true do
    wait(10)
        if fm then
            for i = 1,30 do
                zc.Parent = game.Workspace
                zc.Position = fs.Position
            print("Spawned")
        end
    end
end

I assume it has something to do with it trying to change the position of the model I cloned into the Workspace. I just don't know how to fix this? Trying to spawn them all at that position, not spawn one then change it's position. Any help is greatly appreciated :)

0
Models don't give you position. Use a part inside the model to get a Position. User#11440 120 — 8y

1 answer

Log in to vote
3
Answered by 8 years ago

You actually can't change the position of a model like that because models do not have a position property. The two ways to do this would be:

Use MoveTo.

MoveTo is basically what you're doing. It changes the position of every part in the model to the chosen Vector3. This is most likely the best choice.

local z = game.ReplicatedStorage.Zombie
local zc = z:Clone()
local fm = game.Workspace:FindFirstChild("Map")
local fs = fm:GetChildren("ZSpawn")

while true do
    wait(10)
        if fm then
            for i = 1,30 do
                zc.Parent = game.Workspace
                zc:MoveTo(fs.Position)
            print("Spawned")
        end
    end
end

Use CFrame.

CFraming a part in the model will set that part's position to a certain spot (and other parts in the model spawn relative). The reason this isn't the best is because the zombie may glitch out when spawning.

local z = game.ReplicatedStorage.Zombie
local zc = z:Clone()
local fm = game.Workspace:FindFirstChild("Map")
local fs = fm:GetChildren("ZSpawn")

while true do
    wait(10)
        if fm then
            for i = 1,30 do
                zc.Parent = game.Workspace
                zc.CFrame = CFrame.new(fs.Position)
            print("Spawned")
        end
    end
end

You can't set a part's position because that would break it's joint.

Hope this helped! If so, accept/upvote! If not, burn your computer down.

~Chem

0
On CFraming models: other parts in the model will move iff they are welded together with the part you CFramed. This is why it's possible to set the Player's Torso's CFrame to teleport them (and not kill them) because the body parts and hats are jointed/welded together with a JointInstance. Also, regular (implied) surface joints (e.g. between studs and inlets) won't do. XAXA 1569 — 8y
Ad

Answer this question