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

Creating instances of models?

Asked by 9 years ago

I am trying to spawn a copy of a brick that I made, but it says :Unable to create an Instance of type "modeledAttacker". Here is the code

local base = script.Parent
 local modeledAttacker = game.Workspace.attacker


function createAttacker()
    attacker = Instance.new("modeledAttacker",Workspace) -- problem originates here
    attacker.Position = Vector3.new( -33, 3, 18)
end

createAttacker()

1 answer

Log in to vote
3
Answered by
Sublimus 992 Moderation Voter
9 years ago

Ok, so to create an exact instance of an instance that already exists, use :Clone()

So, to fix your problem:

local base = script.Parent
    local modeledAttacker = game.Workspace.attacker


function createAttacker()
    attacker = modeledAttacker:clone() -- You clone it here
    attacker:MakeJoints() -- Keeps the model together, just to be sure
    attacker.Parent = game.Workspace -- When you clone it the parent defaults to nil
    attacker.Position = Vector3.new( -33, 3, 18)
end

createAttacker()

0
thanks! CaptainRuno 40 — 9y
Ad

Answer this question