How to clone model on script

so i made a script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RevengeEvent = ReplicatedStorage:WaitForChild("RevengeEvent")

RevengeEvent.OnServerEvent:Connect(function(player)
    -- Add your logic here to handle the revenge event
    print(player.Name .. " triggered the revenge event!")
	-- Example: Reduce player's health
	local frametext = player.PlayerGui.DialogGui.DialogFrame.text
	if frametext then
		frametext.Text = "in return..."
		wait(2)
		frametext.Text = "run down the basement"
		wait(2)
		frametext.Text = "3"
		wait(1)
		frametext.Text = "2"
		wait(1)
		frametext.Text = "1"
		wait(1)
		-- here is where i want the clone to happen
	end
end)


and idk how to make it so that after the last wait, a model called “killer” clones from the server storage and its position where it clones will be the Cframe of a part called “killerspawn”

local ModelToClone = game:GetService("ServerStorage").NameOfYourModel
local KillerPart = workspace.killerspawn

--// Clone model
local ClonedModel = ModelToClone:Clone()
ClonedModel:PivotTo(KillerPart.CFrame)

it doesnt work can u show where to add it in my script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RevengeEvent = ReplicatedStorage:WaitForChild("RevengeEvent")

local ModelToClone = game:GetService("ServerStorage").NameOfYourModel
local KillerPart = workspace.killerspawn

RevengeEvent.OnServerEvent:Connect(function(player)
    -- Add your logic here to handle the revenge event
    print(player.Name .. " triggered the revenge event!")
	-- Example: Reduce player's health
	local frametext = player.PlayerGui.DialogGui.DialogFrame.text
	if frametext then
		frametext.Text = "in return..."
		wait(2)
		frametext.Text = "run down the basement"
		wait(2)
		frametext.Text = "3"
		wait(1)
		frametext.Text = "2"
		wait(1)
		frametext.Text = "1"
		wait(1)
		-- here is where i want the clone to happen
        local ClonedModel = ModelToClone:Clone()
        ClonedModel:PivotTo(KillerPart.CFrame)
	end
end)

Credit to Sarchyx for the code from above ^

it doesnt work, this is my script now:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RevengeEvent = ReplicatedStorage:WaitForChild("RevengeEvent")

local ModelToClone = game:GetService("ServerStorage").killer
local KillerPart = workspace.killerspawn

RevengeEvent.OnServerEvent:Connect(function(player)
	-- Add your logic here to handle the revenge event
	print(player.Name .. " triggered the revenge event!")
	-- Example: Reduce player's health
	local frametext = player.PlayerGui.DialogGui.DialogFrame.text
	if frametext then
		frametext.Text = "in return..."
		wait(2)
		frametext.Text = "run down the basement"
		wait(2)
		frametext.Text = "3"
		wait(1)
		frametext.Text = "2"
		wait(1)
		frametext.Text = "1"
		wait(1)
		-- here is where i want the clone to happen
		local ClonedModel = ModelToClone:Clone()
		ClonedModel:PivotTo(KillerPart.CFrame)
	end
end)

Try this clone code:

local killer = game.ServerStorage.Killer:Clone()
killer.Parent = workspace
killer:PivotTo(workspace.killerspawn.CFrame)
1 Like

Is the code reaching the point where the clone happens? Show me the output when you run this script

this worked thanks a lot for it

You forgot to parent it man. Small thing :frowning:

Oh yeah lol I see now… I was just taking the code from the guy who responded first since he asked for the full code

im not much of a scripter so i didnt see that there was no parent thing

also guys 1 more question, how to make it so that after it spawns, how to disable the gui like enabled = false, cuz its not working for me

Disable it on a local script. For maximum efficiency change the remote event you’re using to a remote function and return true to signal success
Client script ig

local gui = -- Gui here
local success = RevengeEvent:InvokeServer()
if success then gui.Enabled = false end

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RevengeEvent = ReplicatedStorage:WaitForChild("RevengeEvent")

RevengeEvent.OnServerInvoke = function(player)
    -- Add your logic here to handle the revenge event
    print(player.Name .. " triggered the revenge event!")
	-- Example: Reduce player's health
	local frametext = player.PlayerGui.DialogGui.DialogFrame.text
	if frametext then
		frametext.Text = "in return..."
		wait(2)
		frametext.Text = "run down the basement"
		wait(2)
		frametext.Text = "3"
		wait(1)
		frametext.Text = "2"
		wait(1)
		frametext.Text = "1"
		wait(1)
        local killer = game.ServerStorage.Killer:Clone()
        killer.Parent = workspace
        killer:PivotTo(workspace.killerspawn.CFrame)
        return true
end

can u tell where to put them and stuff i feel dumb

I stated above. The first piece in a local script (preferably under where the gui is) and the second part can stay wherever it is

for server it can be in serverscriptservice or workspace?

Preferably server script service since its the main hub for server scripts

in the local script one, do i make a var for revengeevent?

I wrote the var even tho i didn’t show it, so do make one

also for the server do i replace it or make a new one like both of them are there ( the old and new one u showed )