Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to have only one clone each time an object clones?

Local Script:

local mouse = game.Players.LocalPlayer:GetMouse()
local throwshurikenAnim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.ThrowShuriken)
script.Parent.Activated:Connect(function()
	if not game.Workspace:FindFirstChild(script.Parent.Parent.Name.."Shuriken") then
		throwshurikenAnim:Play()
		throwshurikenAnim.Stopped:Connect(function()
			game.ReplicatedStorage.Message:FireServer("ThrowShuriken", script.Parent.Handle, mouse.Hit.p)
		end)
	end
end)

ServerScript:

game.ReplicatedStorage.ThrowShuriken.OnServerEvent:Connect(function(player, message, handle, mousepos)
	local debounce = true
	local shuriken = handle:Clone()
	shuriken.Name = player.Name.."Shuriken"
	shuriken.Parent = workspace
	shuriken.CanCollide = false
	shuriken.Position = player.Character.RightHand.Position
	handle.Transparency = 1
	local bodyVelocity = Instance.new("BodyVelocity", shuriken)
	bodyVelocity.Velocity = (mousepos - shuriken.Position).unit*50*Vector3.new(1,0,1)
	local bodyAngularVelocity = Instance.new("BodyAngularVelocity", shuriken)
	bodyAngularVelocity.AngularVelocity = Vector3.new(0, 120, 0)
	debris:AddItem(shuriken,10)
	shuriken.Touched:Connect(function(a)
		print(a.Parent.Name..", "..a.Name)
		if a.Parent.Name ~= player.Name and a.Name ~= "Handle" and a.Name ~= shuriken.Name and debounce == true then
			debounce = false
			if a.Parent:FindFirstChild("Humanoid") then
				a.Parent.Humanoid:TakeDamage(10)
				shuriken:Destroy()
			else
				shuriken.Anchored = true
				print("Anchored")
			end
		end
	end)
	spawn(function()
		repeat wait() until not game.Workspace:FindFirstChild(shuriken.Name)
		handle.Transparency = 0
	end)
end)

When the handle clones the second time, 2 shurikens appear. When it clones the third time, 3 shurikens appear. But I only want 1 to appear each time. How can I fix this?

1 answer

Okay, so this is simple. All you do is...

local exampleModel = game.Workspace.exampleModel

while true do
	wait(60)   -- Replace with however long you want a cooldown
		exampleModel:Destroy()
	wait(0.001)
		exampleModel:Clone()
end)

That was just an example of how you would clone a map or something like that. If you wanted to clone a model for a tool, you would do

local toolModel = game.Workspace.toolModel

while true do
	'wait(60)
		toolModel:Destroy()
	wait(0.001)
		toolModel:Clone()
	wait(0.001)
		toolModel.Parent = game.Players.LocalPlayer.Backpack
end)

That would move the tool to the backpack of the local player.

This discussion is preserved as it was. New answers, comments, and votes are closed.