I am trying to clone a part from replicated storage and into the workspace using Part:Clone(), and then destroying the part after I tween it.
The issue I am facing is that when I clone the part it clones multiple times as in, the first time I use it it produces the part once, the second time I use it, it produces two parts instead of one every time I use the ability.
The tweening isn’t the issue, Ive tried it with and without tweens and the issue remains.
Heres how my script is currently set up.
Local script inside starter character scripts
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.E and gameProcessedEvent == false and os.clock() -
firefliesCoolDown >= 5 then
local mousepos = mouse.Hit.Position
local humRPpos = humanoidRootPart.Position
local distance = ((humRPpos - mousepos).Magnitude)
task.wait()
humanoidRootPart.Anchored = true
firefliesAnim:Play()
firefliesAnimBegin:FireServer(mousepos, distance)
firefliesAnim.Ended:Connect(function()
firefliesAnimEnd:FireServer(mousepos, distance)
firefliesCoolDown = os.clock()
task.wait(1)
humanoidRootPart.Anchored = false
end)
end
end)
Serverscript inside of serverscriptservice
firefliesAnimEnd.OnServerEvent:Connect(function(player, mousepos, distance)
local firefliesClone = fireflies:Clone()
firefliesClone.Parent = game.Workspace
firefliesClone.Position = player.Character.HumanoidRootPart.Position + Vector3.new(-3,1,1)
local goals =
{
Position = mousepos
}
local tweenInfo = TweenInfo.new(
distance/50,
Enum.EasingStyle.Cubic,
Enum.EasingDirection.In,
0,
false,
0
)
local firefliesTween = tweenService:Create(firefliesClone,tweenInfo, goals)
firefliesTween:Play()
firefliesTween.Completed:Connect(function()
firefliesClone.ParticleEmitter:Emit(100)
task.wait(0.95)
firefliesClone:Destroy()
firefliesTween:Destroy()
end)
end)
If what I’m saying is confusing and you need clarification tell me and I can try and explain it in a more understandable manner.
Edit: here is my issue recorded… https://youtu.be/6_97Xj3GDnk