Meteor Infinitely Damages Player

I’m trying to make a meteor in my game that spawns around maps randomly, but I’m having problems with it.

While I was trying to make it damage the player, I noticed that it never stopped and kept damaging the player, and so I made a table to filter out players who have already been hit by the meteor. But for some reason the meteor continues to constantly damage the player, killing them.

There are no error’s, here’s the script.

local Meteor = workspace:WaitForChild("Meteor")

function summonMeteor()
	local Connection
	
	local hitTable = {}
	local newMeteor = Meteor:Clone()
	newMeteor.Parent = workspace
	
	local InsideImpact = newMeteor:WaitForChild("InsideImpact")
	local OutsideImpact = InsideImpact:WaitForChild("OutsideImpact")
	local hitbox = newMeteor:WaitForChild("hitbox")
	local summoningSound = newMeteor:WaitForChild("summoningSound")
	local meteorSmash = newMeteor:WaitForChild("meteorSmash")
	
	-- InsideImpact.CFrame = InsideImpact.CFrame * CFrame.new(math.random(-30, 30), 0, math.random(-30, 30))
	OutsideImpact.CFrame = InsideImpact.CFrame
	
	newMeteor.CFrame = InsideImpact.CFrame * CFrame.new(math.random(-360, 360), 250, math.random(-360, 360))
	
	local tween = game:GetService("TweenService"):Create(newMeteor, TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {
		CFrame = InsideImpact.CFrame
	})
	
	summoningSound:Play()

	tween:Play()
	
	tween.Completed:Wait()
	
	meteorSmash:Play()
	newMeteor.Transparency = 1
	newMeteor.Fire:Destroy()
	
	hitbox.CFrame = newMeteor.CFrame
	hitbox.Transparency = 0
	hitbox.SelectionSphere.Transparency = 0
	
	local hitboxTween = game:GetService("TweenService"):Create(hitbox, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0), {
		Size = Vector3.new(52, 52, 52)
	})
	
	local hitboxTransparencyTween = game:GetService("TweenService"):Create(hitbox, TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0), {
		Transparency = 1
	})
	
	local selectionSphereTween = game:GetService("TweenService"):Create(hitbox.SelectionSphere, TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0), {
		Transparency = 1
	})
	
	hitboxTween:Play()
	hitboxTransparencyTween:Play()
	selectionSphereTween:Play()
	
	local hitTable = {}
	
	Connection = hitbox.Touched:Connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if player and hitTable[player.Character] == nil then
			player.Character:FindFirstChildOfClass("Humanoid"):TakeDamage(50)
			table.insert(hitTable, player.Character)
			print(hitTable)
		end
	end)
	
	hitboxTween.Completed:Connect(function()
		Connection:Disconnect()
	end)
	
	task.delay(5, game.Destroy, newMeteor)
end

for i = 1, 100  do
	task.wait(2)
	
	summonMeteor()
end

what does the output print?
is it spamming you with the hit table?

Yes it is, and for some reason my name gets indexed like 100 times…

try to use and not table.find(player.Character.Name)

local hitTable = {}
	
	Connection = hitbox.Touched:Connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if player and not table.find(player.Character.Name) then
			player.Character:FindFirstChildOfClass("Humanoid"):TakeDamage(50)
			table.insert(hitTable, player.Character.Name)
			print(hitTable)
		end
	end)

also try putting the hittable outside the function

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.