Main Issue:
Our goal here is to get a instant amount of all the parts that were exploded. We have added +1 to the amount each time explosion.hit was fired. It prints the amount inside of the event immediately but outside the event it prints 0 each time.
The code:
local amount = 0
explosion.Hit:Connect(function(part)
--LEAVE----------------------------------------------------
if part.Parent == nil then return end
-----------------------------------------------------------
if not CanFire(player, part.Parent.Parent.Parent) then return end
--BASIC CHECKS---------------------------------------------
if not part:IsA("BasePart") then return end
-----------------------------------------------------------
local numberValue = part.Parent.Parent.Parent.Configuration.RemovedParts
amount += 1
numberValue.Value += 1
end)
print(amount)
Please let us know if there are any solutions to this! Thank you.
I am pretty sure you should put the print statement inside the event (at the end)
Edit: Also you should probably put the very first line in the script as the first line inside the event, so that it resets each time (assuming you only want the amount of parts for that specific time)
We’ve tired this the problem is we want to be able to get the entire value of all the parts that were hit by an explosion. This just gives us each individual part.
local amount = 0
local explosion = Instance.new("Explosion")
explosion.Parent = game.Workspace.SpawnLocation
for _, plr in game.Players:GetPlayers() do
local dist = (explosion.Position - plr.Character.PrimaryPart.Position).Magnitude
if dist >= explosion.BlastRadius then
task.wait(5) -- wait for explosion to be done? idk if there's a better method
for _, bodypart in plr.Character:GetChildren() do
if bodypart:IsA("BasePart") then
amount += 1
end
end
end
end
print(amount.. "Body Limbs left!")