#projectile help!
24 messages · Page 1 of 1 (latest)
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)
Watch example! and millions of other Roblox Studio videos on Medal, the largest Game Clip Platform.
Are you looking to only make it deal damage once and then be destroyed?
yes, exactly that!
like thisss no?
orwoul i put it somewhere else
Oh u already have it
Idk why it's still firing then
Just connect to touch using :Once instead of :Connect @dreamy pine
Peak
tysm!
Wait there's an edge case tho
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
Like you mean if it hits thee useers char instead of an eenemy char?
What you could do is pass the connection as an argument to your hit function
Ye
@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
Okay
** You are now Level 2! **