How to put this cloning script into this script?

Hello,

So i’ve been working with remote functions lately, so no hacker/exploiter can give themself cash.

But I want to have the cloning script in the server script so it can return the cloned model when the player clicks the purchase button and that it checks if the player has enough cash to buy it.

And if they have enough cash then the model will be getting cloned from replicated storage.

Can someone help me with this?

(The scripts arent putted in one script yet!)

Here’s the cloning script;

local tvclone = game.ReplicatedStorage.Tvs.OldTv.PartsOfOldTv:Clone()
	tvclone.Parent = game.Workspace
	local position = game.ReplicatedStorage.Tvs.OldTv.PartsOfOldTv.Screen


	for i, v in pairs(tvclone:GetChildren()) do
		v.Anchored = false
		v.CanCollide = true
		v.Transparency = 0
	end

	-- positions	
	local rotatepositionCFrame = CFrame.Angles(0,math.rad(0), 0)
	position.CFrame = position.CFrame:ToWorldSpace(rotatepositionCFrame)
	print("The CFrame has been set")
	
	wait(30)
	print("30 Seconds are over!")
	script.Parent.Parent.Parent.BackGround.OldTv.PriceSetter.Visible = false
	script.Parent.Parent.Parent.BackGround.OldTv.Selection.Visible = true
	script.Disabled = false
	print("PurchaseScript has been enabled")

Here’s the server script; in this script needs to be the cloning script too.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local createPartRequest = Instance.new("RemoteFunction")
createPartRequest.Parent = ReplicatedStorage
createPartRequest.Name = "CreatePartRequest"

local function onCreatePartRequested(player)
	
	
	return -- the cloned model idk if I need to usse metatables to put all the cloning lines into one name.
end

createPartRequest.OnServerInvoke = onCreatePartRequested

Here’s is the client script;

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local createPartRequest = ReplicatedStorage:WaitForChild("CreatePartRequest")

script.Parent.Activated:Connect(function()
	local (-the name of the model-) = createPartRequest:InvokeServer(game:GetService("Players").LocalPlayer)

end)

From what I see, it does clone it, but here

you use replicated storage and not the clone of it. Use the clone of it like this and it should work:

local position = tvclone.Screen

Thats not the problem I mean how do I need to put the cloning script into the server script so it can return the model when they have enough cash.

Then I believe shoving the cloning into the function should do what you’re asking here

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local createPartRequest = Instance.new("RemoteFunction")
createPartRequest.Parent = ReplicatedStorage
createPartRequest.Name = "CreatePartRequest"

local function onCreatePartRequested(player)
	local tvclone = game.ReplicatedStorage.Tvs.OldTv.PartsOfOldTv:Clone()
	tvclone.Parent = game.Workspace
	local position = tvclone.Screen


	for i, v in pairs(tvclone:GetChildren()) do
		v.Anchored = false
		v.CanCollide = true
		v.Transparency = 0
	end

	-- positions	
	local rotatepositionCFrame = CFrame.Angles(0,math.rad(0), 0)
	position.CFrame = position.CFrame:ToWorldSpace(rotatepositionCFrame)
	print("The CFrame has been set")
	
	wait(30)
	print("30 Seconds are over!")
	script.Parent.Parent.Parent.BackGround.OldTv.PriceSetter.Visible = false
	script.Parent.Parent.Parent.BackGround.OldTv.Selection.Visible = true
	script.Disabled = false
	print("PurchaseScript has been enabled")
	
	return -- the cloned model idk if I need to use metatables to put all the cloning lines into one name.
end

createPartRequest.OnServerInvoke = onCreatePartRequested

Yea I know that but after return there has to be a name so it can return the clone.

So, do I need to use metatables or something?