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

What should I do with doing Humanoid:TakeDamage() 'simultaneously'?

I have been working on a project for quite a while. I created a First Person Shooter module and added multiple bullet shots (shotguns). However, whenever I damage a zombie with the spread, it only deals damage once (15 damage). Same applies for all of the shotguns. I have printed marking places and have checked that the code still runs. But it only does one shot of damage!

Sometimes it will do the correct amount of damage and kill the zombie!

Is this a Roblox base code issue or me?

PS I tried posting on roblox dev forum but didnt verify me even after 32 mins read time -_- PPS I realized when this problem happened it made the zombie's health bar flash red?

if roundArray then
			for i = 1, #roundArray do
				print(roundArray[i][1],"|",roundArray[i][2],"|",roundArray[i][3],"|",roundArray[i][4],"|",roundArray[i][5])
				if roundArray[i][3] ~= nil then
					hit = roundArray[i][3]
					print(hit)
					if hit.Parent.Name == "Zombie" then
						enemyHum = hit.Parent:FindFirstChild("Zombie")
						
						if hit.Name == "Head" then
							damage = self.settings.damageFunc()*1.5
						else
							damage = self.settings.damageFunc()
						end
						
						print("Enemy:", enemyHum)
						enemyHum:TakeDamage(damage)
						print(damage, "\n")
						
						marker = game:GetService("ReplicatedStorage").HitMarker:Clone()
						marker:FindFirstChild("TextLabel").Text = damage
						marker.Parent = game.Players.LocalPlayer.PlayerGui
						marker.Adornee = hit
						marker.Enabled = true
						
						if hit.Name == "Head" then
							marker.TextLabel.TextColor3 = Color3.new(1, 1, 0)
						end
					end
				end
			end
		end

2 comments

0

I'm not sure if this is memory efficient, but a simple way to do it is to put a ServerScript inside of the bullet to be cloned, and check if it has been touched by a part, if it is, check for a humanoid. If there's a humanoid, then if it's not an actual player, then take damage. Not sure, just a guess.

0

Sorry about being unclear; I am using raycasting and roundArray is a list which I am iterating through in order to calculate those extra rays. Hope this cleared something up!

2 answers

✓ Accepted answer

So after briefly looking at your script, I'd say you should use a for loop (which you've done), then use spawn(function() end) to take damage, for each bullet (which you've said that you use RayCasting for).

1 comment

0

yeah i have tried that, by starting multiple threads but it still doesnt work. Where should i place spawn()?

I managed to fix this by telling remoteEvent to do damage to the server side

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