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

My Radius Damage isn't taking damage?

local Shark = script.Parent
local Distance = 15


for _, player in pairs(game.Players:GetPlayers()) do
	if player.Character ~= nil and player:DistanceFromCharacter(Shark.Position) <= Distance then
		player.Character:FindFirstChild("Humanoid"):TakeDamage(5)
	end
end

The purpose of this script is that if you come within 15 studs of the shark, you'll take 5 damage. However, it isn't working and it isn't showing anything in the output.

1 answer

✓ Accepted answer

The problem here is that the code only runs once. Use some form of loop, like so:

local Distance = 15
local TimeInBetweenDamage = 3

local Shark = script.Parent

while wait(TimeInBetweenDamage) do
	for _, player in pairs(game.Players:GetPlayers()) do
		if player.Character and player:DistanceFromCharacter(Shark.Position) <= Distance then
			player.Character:FindFirstChild("Humanoid"):TakeDamage(5)
		end
	end
end

TIP:

Format your code using Tab instead of Space, because it is more consistent and efficient.


Hope I helped!

~TDP

2 comments

0

It's my understanding that when copying code, the tabs get converted to spaces.

0

Really? I copy code all the time and the formatting works. Either way, put in the extra effort, cause it's hell reformatting code lol

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