What do you want to achieve? Keep it simple and clear!
A rocket launcher but I want to make the explosion do less damage
What is the issue? Include screenshots / videos if possible!
the explosion won’t do less damage
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
try searching but still haven’t found a solution
script.Parent.Shoot.OnServerEvent:Connect(function(player, LookAt)
local offset = Vector3.new(0,-2.5,-2.5)
local missle = Instance.new("Part",workspace)
missle.CFrame = script.Parent.Head.CFrame*CFrame.new(offset)
missle.Velocity = LookAt * 100
missle.Material = "Neon"
missle.BrickColor = BrickColor.new("Really red")
missle.Size = Vector3.new(1,1,1)
missle.Transparency = 0.3
local fly = Instance.new("BodyForce",missle)
fly.Force = Vector3.new(0,missle:GetMass()*196.2,0)
game.Debris:AddItem(missle,10)
sound:Play()
wait()
missle.Touched:Connect(function()
local s = Instance.new("Sound")
s.Parent = missle
s.SoundId = 'rbxassetid://3802270540'
s.Volume = 10
s:Play()
local MIN_DAMAGE = 20
local MAX_DAMAGE = 30
local e = Instance.new("Explosion",workspace)
e.Position = missle.Position
e.DestroyJointRadiusPercent = 0
e.Hit:Connect(function(hit, distance)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
hum:TakeDamage((1 - distance / e.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
missle:remove()
else
missle:remove()
end
end)
end)
end)
2 Likes
What’s this formula for? Why did you subtract max from min?
Edit: Minor thing but get rid of the else condition, and do this.
if hum then
hum:TakeDamage((1 - distance / e.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
missle:remove()
Hm, the explosion still instant kill players, I tried to change the take damage to normal numbers but still won’t work
PapaBreadd
(PapaBreadd)
September 30, 2021, 3:27am
4
Your formula looks fine
Have you tried adding a debounce to the .touched function?
(Edit, Actually probably just prevent the touched function from running again once its been touched once)
The reason is because your explosion hits every part of the player (limbs, hats, etc.) and it treats each part like it belongs to a completely new target.
You’ll want to add an array of all players who’ve already been hit once by the explosion. Add a check where if a player was already hit and is in the array, don’t deal damage. If a player is hit for the first time, damage them, then add them to the array.
1 Like
How would I do that? I am not a scripter, the code above is just me mixing everything together
you should add a debounce so the bomb only damages the player one time instead of damaging the player everytime the script detects a touch.
it’s actually pretty simple.
local debounce
if not debounce then
missle.Touched:Connect(function()
debounce = true -- so the script wouldn't run again
-- your script
end
end
try use this script
onehit = true
script.Parent.Shoot.OnServerEvent:Connect(function(player, LookAt)
local offset = Vector3.new(0,-2.5,-2.5)
local missle = Instance.new("Part",workspace)
missle.CFrame = script.Parent.Head.CFrame*CFrame.new(offset)
missle.Velocity = LookAt * 100
missle.Material = "Neon"
missle.BrickColor = BrickColor.new("Really red")
missle.Size = Vector3.new(1,1,1)
missle.Transparency = 0.3
local fly = Instance.new("BodyForce",missle)
fly.Force = Vector3.new(0,missle:GetMass()*196.2,0)
game.Debris:AddItem(missle,10)
sound:Play()
wait()
missle.Touched:Connect(function()
local s = Instance.new("Sound")
s.Parent = missle
s.SoundId = 'rbxassetid://3802270540'
s.Volume = 10
s:Play()
local MIN_DAMAGE = 20
local MAX_DAMAGE = 30
local e = Instance.new("Explosion",workspace)
e.Position = missle.Position
e.DestroyJointRadiusPercent = 0
e.Hit:Connect(function(hit, distance) if onehit == true then onehit = false
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
hum:TakeDamage((1 - distance / e.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
missle:remove()
wait(0.1)
onehit = true
else
missle:remove()
end
end
end)
end)
end)