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

Can you make custom parts that can be summoned in with an Instance command?

Asked by 6 years ago

Question is pretty much self explanatory, let's say I made a flag, could I assign it to 'flag' and run Instance.new('flag') to get it to spawn in?

2 answers

Log in to vote
0
Answered by 6 years ago

put this in a local script a place it into the startergui.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local command = "Your command here"

game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
    if string.sub(msg,1) == command then
        local flag-- = your object here
        local flagclone = flag:Clone()
        flagclone.Parent = workspace

        if flagclone:IsA("Model") then
            if flagclone.PrimaryPart then
                for i,v in pairs(flagclone:GetChildren()) do
                    if v:IsA("BasePart") then
                        v.Anchored = true
                    end
                end
                flagclone:SetPrimaryPartCFrame(char.HumanoidRootPart.CFrame* CFrame.new(0,0,-3))
            end
        elseif flagclone:IsA("BasePart") then
            flagclone.Anchored = true
            flagclone.CFrame = char.HumanoidRootPart.CFrame* CFrame.new(0,0,-3)
        end
    end
end)
0
Thanks :) JackMills 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

No, but however you make the flag, you could store it somewhere (ex in ReplicatedStorage) and :Clone() it when you want another one. (If it's a Model, you may need to :MakeJoints() after you Clone it). ex:

local origFlag = game.ReplicatedStorage.Flag
--When you want a new one:
local newFlag = origFlag:Clone()
newFlag:MakeJoints()
newFlag.Parent = workspace

You can have scripts inside the flag if you want special functionality. Alternatively, you can make your own function in (for example) a ModuleScript that creates the flag, sets up events, and anything else you want.

Answer this question