While I spot one issue with the code here, I don’t think the multiplying is coming from this script, but rather the script firing it. For this one, your issue (minor) would be with the destroying event, which will add multiple connections and assumably cause errors. Simple fix for this is add a variable for the connection and disconnect the connection:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShieldEvent = ReplicatedStorage.AbilitiesEvents:WaitForChild("ShieldEvent")
local DestroyShieldEvent = ReplicatedStorage.AbilitiesEvents:WaitForChild("DestroyShieldEvent")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
ShieldEvent.OnServerEvent:Connect(function(player, Character, MousePosition, Name)
local Path = game.ReplicatedStorage.Powers:FindFirstChild(Name)
local HumanoidRootPart = Character.HumanoidRootPart
local Shield = Path.Shield:Clone()
Shield.Parent = game.Workspace
Shield.CFrame = HumanoidRootPart.CFrame
local Weld = Instance.new("Weld", HumanoidRootPart)
Weld.C0 = CFrame.new()
Weld.C1 = CFrame.new()
Weld.Part0 = HumanoidRootPart
Weld.Part1 = Shield
local ShieldTween = TweenService:Create(Shield, TweenInfo.new(1), {Size = Vector3.new(8, 8, 8), Transparency = 0})
ShieldTween:Play()
local DestroyConnection
DestroyConnection = DestroyShieldEvent.OnServerEvent:Connect(function()
DestroyConnection :Disconnect()
local DestroyShieldTween = TweenService:Create(Shield, TweenInfo.new(1), {Transparency = 1})
DestroyShieldTween:Play()
DestroyShieldTween.Completed:Wait()
Shield:Destroy()
Weld:Destroy()
end)
end)
Would you provide the script that fires the event?
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShieldEvent = ReplicatedStorage.AbilitiesEvents:WaitForChild("ShieldEvent")
local DestroyShieldEvent = ReplicatedStorage.AbilitiesEvents:WaitForChild("DestroyShieldEvent")
local Tool = script.Parent
Tool.Equipped:Connect(function()
local Name = player.Character.CharacterName.Value
local LeftCharge = game.ReplicatedStorage.Powers:FindFirstChild(Name).Charge.Charge:Clone()
local RightCharge = game.ReplicatedStorage.Powers:FindFirstChild(Name).Charge.Charge:Clone()
LeftCharge.Parent = Character.LeftHand
RightCharge.Parent = Character.RightHand
local RandomAnimation = script:GetChildren()[math.random(1, #script:GetChildren())]
local ChargingAnimation = player.Character.Humanoid:LoadAnimation(RandomAnimation)
local ShieldAnimation = player.Character.Humanoid:LoadAnimation(script.Parent.ShieldAnimation)
ChargingAnimation:Play()
Tool.Activated:Connect(function()
ChargingAnimation:Stop()
ShieldAnimation:Play()
local MousePosition = mouse.Hit.Position
ShieldEvent:FireServer(Character ,MousePosition, Name)
end)
Tool.Unequipped:Connect(function()
DestroyShieldEvent:FireServer()
LeftCharge:Destroy()
RightCharge:Destroy()
ChargingAnimation:Stop()
ShieldAnimation:Stop()
end)
end)