#projectile help!

24 messages · Page 1 of 1 (latest)

dreamy pine
#

hello was wondering how to make projectile only damage once even if it hits two body part at the same time

#

local RS = game:GetService("ReplicatedStorage")
local RNS = game:GetService("RunService")

local shootRE = RS:WaitForChild("ShootRE")
local projectileTemplate = RS:WaitForChild("Projectile")

local distance = 45
local speed = 1
local velocity = speed * 60
local lifetime = distance/velocity

local function hit(projectile, otherPart, playerCharacter)
if otherPart.Parent == playerCharacter then return end
projectile:Destroy()
print(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(10)
end
end

local function shoot(player)
local projectile = projectileTemplate:Clone()

local character = player.Character
local rootPart = character.HumanoidRootPart

projectile.Parent = workspace.ProjectileHandlerFolder
projectile.Position = rootPart.CFrame.Position + rootPart.CFrame.LookVector * 1
projectile.Orientation = Vector3.new(0, rootPart.Orientation.Y, 0)

RNS.Heartbeat:Connect(function(deltaTime)
    --print(deltaTime)
    projectile.Position = projectile.Position + projectile.CFrame.LookVector * speed
end)

game.Debris:AddItem(projectile, lifetime)

projectile.Touched:Connect(function(otherPart)
    hit(projectile, otherPart, character)
    
end)

end

shootRE.OnServerEvent:Connect(shoot)

clever basin
clever basin
#

Destroy the projectile in your hit function?

dreamy pine
#

orwoul i put it somewhere else

clever basin
#

Idk why it's still firing then

#

Just connect to touch using :Once instead of :Connect @dreamy pine

clever basin
#

If the hit part is the player character then you return cuz u don't wanna have the bullet affect it

#

But this way if it is the player character it'll still stop calling your function even if it hits smth

dreamy pine
clever basin
#

What you could do is pass the connection as an argument to your hit function

clever basin
#

@dreamy pine make the connection a variable and change :Once to :Connect again

#

Then in your hit function just game the connection as a parameter and disconnect it there

ebon ermineBOT
#

studio** You are now Level 2! **studio