When the part is touched it is supposed to damage the player once but I can’t figure out how to make the part only damage the player once. Here is the server script.
local fireballRM = game.ReplicatedStorage.Fireball
local tool = script.Parent
local addCoins = require(game.ReplicatedStorage.CoinFunctions)
local canUseAbility = true
local playerService = game:GetService("Players")
fireballRM.OnServerEvent:Connect(function(plr)
if tool.Parent == plr.Character and canUseAbility then
canUseAbility = false
local Sound = Instance.new("Sound", game.Workspace)
Sound.Volume = 0.5
Sound.Looped = false
Sound.SoundId = "rbxassetid://5312934759"
Sound.Volume = 0.5
Sound:Play()
local HRP = plr.Character.HumanoidRootPart
local Part = Instance.new("Part" ,workspace) -- the part to move
local flame = Instance.new("Fire", Part)
Part.CanCollide = false
Part.Shape = Enum.PartType.Ball
Part.CFrame = HRP.CFrame -- Putting the part infront of the player
Part.Color = Color3.new(1, 0, 0)
Part.Material = Enum.Material.Neon
local Attachment = Instance.new("Attachment", Part) -- the attachment used in Linearvelocity
local LV = Instance.new("LinearVelocity", Attachment) -- creating the linear velocity
LV.MaxForce = math.huge -- no need to worry about this
LV.VectorVelocity = HRP.CFrame.lookVector * 100 -- change 100 with how fast you want the projectile to go
LV.Attachment0 = Attachment -- setting the attachment
Part.Touched:Connect(function(hit)
local canDmg = true
if hit.Parent.Humanoid ~= plr.Character.Humanoid and canDmg then
addCoins.DamageReward(5, 1, playerService:GetPlayerFromCharacter(tool.Parent))
if canDmg then
hit.Parent.Humanoid:TakeDamage()
end
Part:Destroy()
end
end)
game.Debris:AddItem(Part, 3) -- deletes the moving part after 2 second
task.wait(15)
canUseAbility = true
end
end)
Thanks for any help.