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

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

Asked by 4 years ago

Local Script:

01local mouse = game.Players.LocalPlayer:GetMouse()
02local throwshurikenAnim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.ThrowShuriken)
03script.Parent.Activated:Connect(function()
04    if not game.Workspace:FindFirstChild(script.Parent.Parent.Name.."Shuriken") then
05        throwshurikenAnim:Play()
06        throwshurikenAnim.Stopped:Connect(function()
07            game.ReplicatedStorage.Message:FireServer("ThrowShuriken", script.Parent.Handle, mouse.Hit.p)
08        end)
09    end
10end)

ServerScript:

01game.ReplicatedStorage.ThrowShuriken.OnServerEvent:Connect(function(player, message, handle, mousepos)
02    local debounce = true
03    local shuriken = handle:Clone()
04    shuriken.Name = player.Name.."Shuriken"
05    shuriken.Parent = workspace
06    shuriken.CanCollide = false
07    shuriken.Position = player.Character.RightHand.Position
08    handle.Transparency = 1
09    local bodyVelocity = Instance.new("BodyVelocity", shuriken)
10    bodyVelocity.Velocity = (mousepos - shuriken.Position).unit*50*Vector3.new(1,0,1)
11    local bodyAngularVelocity = Instance.new("BodyAngularVelocity", shuriken)
12    bodyAngularVelocity.AngularVelocity = Vector3.new(0, 120, 0)
13    debris:AddItem(shuriken,10)
14    shuriken.Touched:Connect(function(a)
15        print(a.Parent.Name..", "..a.Name)
View all 31 lines...

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

Log in to vote
0
Answered by 4 years ago

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

1local exampleModel = game.Workspace.exampleModel
2 
3while true do
4    wait(60)   -- Replace with however long you want a cooldown
5        exampleModel:Destroy()
6    wait(0.001)
7        exampleModel:Clone()
8end)

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

01local toolModel = game.Workspace.toolModel
02 
03while true do
04    'wait(60)
05        toolModel:Destroy()
06    wait(0.001)
07        toolModel:Clone()
08    wait(0.001)
09        toolModel.Parent = game.Players.LocalPlayer.Backpack
10end)

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

Ad

Answer this question