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