Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Rockt Launcher Only Kills Humanoid With A Direct Hit?

I wanted to make a rocket launcher that can kill humanoids without destroying joints. I followed a tutorial on wiki. This is the part of the rocket script that I changed while the other parts are irrelevant. But, I can only kill the humanoid when I shoot a direct hit into them. If I shoot around their bodies, it doesn't effect them, which it should!

function blow(hit)
	Hit = hit
	plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if hit.Parent.Name ~= ("Door1") and hit.Parent.Name ~= ("Soldier") and hit.Parent.Name ~= ("Door") and hit.Parent.Name ~= ("Governor") and hit.Parent.Name ~= ("Emperor") and not plr then
	swoosh:stop()
	explosion = Instance.new("Explosion")
	explosion.Position = shaft.Position
	explosion.DestroyJointRadiusPercent = 0
elseif plr.TeamColor ~= script.Parent.Parent.Parent.TeamColor then
	swoosh:stop()
	explosion = Instance.new("Explosion")
	explosion.Position = shaft.Position
	explosion.DestroyJointRadiusPercent = 0
	end


	-- find instigator tag
	local creator = script.Parent:findFirstChild("creator")
		explosion.Hit:connect(function(hitPart, partDistance)  onPlayerBlownUp(hitPart, partDistance, creator)
		 if creator ~= nil and not plr and hit.Parent.Name ~= ("Soldier") then
		local maxDamage = 1000
		 local humanoid = hitPart.Parent and hitPart.Parent:FindFirstChild("Humanoid")
	   local plr = game.Players:GetPlayerFromCharacter(hitPart.Parent)
	if humanoid and humanoid.Parent.Name ~= ("Soldier") and not plr then
	       local distance_factor = partDistance / explosion.BlastRadius    -- get the distance as a value between 0 and 1
	    distance_factor = 1 - distance_factor -- flip the amount so that lower == closer == more damage
	        humanoid:TakeDamage(maxDamage*distance_factor)                -- 0: no damage; 1: max damage
	    end
	end
end)

All help appreciated.

2 answers

✓ Accepted answer

You were missing an end in the first function, just before the existing end put another to end the "elseif" statement. You should also probably put the stuff after "onPlayerBlowUp(hitPart, partDistance, creator)" inside the function itself (not after the call) and remove any existing damage dealt in there.

This discussion is preserved as it was. New answers, comments, and votes are closed.