Cloning another model when the first model already is cloned

Hello,

So what I want to do is that when a player clicks on a button that the first model gets cloned(I already have that, and that works fine) but I also want that when a player clicks the button for the second time that the other model gets cloned.

Can you help me with this?

Here’s the script that clones the first model;

local hover = game.SoundService.HoverSound

script.Parent.MouseEnter:Connect(function()
	hover:Play()
end)

local player = game.Players.LocalPlayer
local Cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
local leaderstats = player.leaderstats

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.PurchaseScript.Disabled = true
	print("Script Disabled!")
	
	Cash.Value = Cash.Value - 500
	
	script.Parent.Parent.Visible = false
	
	wait(2.5)
	
	local tvmakerclone1 = game.ReplicatedStorage.TvMakers.TvMakerLVL1
	tvmakerclone1.Parent = game.Workspace
	
	wait(30)
	script.Parent.PurchaseScript.Disabled = false
	print("Script has been enabled!")
-- somewhere in this script needs to be the other clone but I dont know where and how.
end)
1 Like

Hiya! I see that you’re doing everything locally, which means that cloning the model, updating the leaderstats etc. will only happen for that player. Use remote events to communicate between the client and server.

As for your question, what you can do is:
Insert an IntValue, and every time the player clicks the button, you can add 1 to the IntValue, and depending on the number of clicks you can clone your model.

If you need any help with the code, please do let me know.

2 Likes

So when a player clicks the button 1 will be added to the IntValue and when the intvalue reaches for example 5 or something like that it will clone the model?

Or is it totally not that?? Please reply

Can you show me an example please? That would really help me

Hiya! So let’s say when the player clicks the button once, it clones “Model1”, and when the player clicks the button twice, it cloned “Model2”. So what we can do is:

LocalScript under the button:

local Button = script.Parent
local Clicks = Button.Clicks

Button.MouseButton1Click:Connect(function()
	Clicks.Value = Clicks.Value + 1
	game.ReplicatedStorage.RemoteEvent:FireServer(Clicks.Value)
end)

Clicks is the name of the IntValue under the Button
Also, insert a RemoteEvent into ReplicatedStorage

Script in ServerScriptService:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, x)
	if x == 1 then
		local modelClone1 = game.ServerStorage.Model1:Clone()
		modelClone1.Parent = game.Workspace
	elseif x == 2 then
		local modelClone2 = game.ServerStorage.Model2:Clone()
		modelClone2.Parent = game.Workspace
	end
end)

Here Model1 is the Model which is cloned when the player clicks the button once.
Model2 is the Model which is cloned when the player clicks the button twice.
Both of these models are stored in ServerStorage. You can go on adding more lines, for ex. If you want another model to be cloned after 3 clicks, you can just add:

elseif x == 3 then
	local modelClone3 = game.ServerStorage.Model3:Clone()
	modelClone3.Parent = game.Workspace
end

Sorry for the late reply. If this isn’t what you mean, or if the code doesn’t work please let me know and I’ll be happy to help!

1 Like

Sorry but I already figured it out but thanks for replying im sure your script is going to work as well!! :wink: :ok_hand: And i just tested it out and it gives no error and it works perfectly!

1 Like

No worries! Good luck developing!