The explosion works perfectly with 1 player, but more than one and it starts to go all weird, any help?
robloxapp-20250222-0639134.wmv (5.0 MB)
We’ll need to see the code, and a bit of an explanation on what makes it “weird”
The explanation is that it isnt supposed to be dealing damage to any of the players characters, but this only works with one player, where adding a second player means that there is damage for some reason.
I will try and get the code back up in a bit but you are going to have to wait a bit sorry
local function SplashDamage(Player, HitPosition)
local Explosion = config.SplashTemplate:Clone()
Explosion.Parent = config.SplashContainer
Explosion.InnerShell.Position = HitPosition
Explosion.OuterShell.Position = HitPosition
Explosion.InnerShell.Size = Vector3.new(config.SplashSize * 0.9, config.SplashSize * 0.9, config.SplashSize * 0.9)
Explosion.OuterShell.Size = Vector3.new(config.SplashSize, config.SplashSize, config.SplashSize)
local touching = workspace:GetPartsInPart(Explosion.OuterShell)
local damagedHums = {}
for i, v in pairs(touching) do
for I,V in pairs(game.Players:GetChildren()) do
if v.Parent.Name == V.Name and config.LaunchTeammates == true then
v.Parent:SetAttribute("IsRagdoll", true)
v.Parent.Torso.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Parent.HumanoidRootPart.Position).Unit *- config.SplashPressure
task.wait()
task.delay(0.01 * config.SplashPressure / 2,function()
player.Character:SetAttribute("IsRagdoll", false)
end)
elseif v.Parent.Name == V.Name and config.LaunchTeammates == false then
if v.Parent.Name == Player.Name then
v.Parent:SetAttribute("IsRagdoll", true)
v.Parent.Torso.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Parent.HumanoidRootPart.Position).Unit *- config.SplashPressure
task.wait()
task.delay(0.01 * config.SplashPressure / 2,function()
player.Character:SetAttribute("IsRagdoll", false)
end)
end
end
if not (v.Parent.Name == V.Name) then
if v.Parent:FindFirstChild("Humanoid") and not damagedHums[v.Parent.Humanoid] and v.Name == "HumanoidRootPart" then
v.Parent.Humanoid:TakeDamage(config.SplashDamage)
damagedHums[v.Parent.Humanoid] = true
if v.Parent.Humanoid.Health <= 0 then
v.Parent.HumanoidRootPart.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Parent.HumanoidRootPart.Position).Unit *- config.SplashPressure
end
elseif v:HasTag("Prop") and not v.Parent:FindFirstChild("Humanoid") then
v.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Position).Unit *- config.SplashPressure / 10
v.AssemblyAngularVelocity = Vector3.new(math.random(0, 45), math.random(0, 45), math.random(0, 45))
end
end
end
end
wait(0.25)
Explosion:Destroy()
end
This Is the code that i have
– Sorry for being so late ive just slept through the day
Can we see the explorer? What is v.Parent
and what is its name? In this case, by the script, v.Parent should be the character and v is a body part of that character
Your code is a bit confusing, why do you go through every player each touching part.
Can’t you just get the player using game.Players:GetPlayerFromCharacter()
or game.Players:FindFirstChild()
?
for i, v in pairs(touching) do
local player = game.Players:FindFirstChild(v.Parent.Name)
end
also player
here is never defined?
I’m super confused as to what you are trying to do with this code.
basically, if i have the setting launchteammates as true, then the teammates should be launched - without hurting anyone - , otherwise, it should only damage any non player rig that comes into it, and only launch the player that fired it
What is the point of going through all the players then?
That just breaks the code.
It’s just makes it so when one player makes an explosion all players do.
Try this
local function SplashDamage(Player, HitPosition)
local Explosion = config.SplashTemplate:Clone()
Explosion.Parent = config.SplashContainer
Explosion.InnerShell.Position = HitPosition
Explosion.OuterShell.Position = HitPosition
Explosion.InnerShell.Size = Vector3.new(config.SplashSize * 0.9, config.SplashSize * 0.9, config.SplashSize * 0.9)
Explosion.OuterShell.Size = Vector3.new(config.SplashSize, config.SplashSize, config.SplashSize)
local touching = workspace:GetPartsInPart(Explosion.OuterShell)
local damagedHums = {}
for i, v in pairs(touching) do
if v.Parent.Name == Player.Name and config.LaunchTeammates == true then
v.Parent:SetAttribute("IsRagdoll", true)
v.Parent.Torso.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Parent.HumanoidRootPart.Position).Unit *- config.SplashPressure
task.wait()
task.delay(0.01 * config.SplashPressure / 2,function()
v.Parent:SetAttribute("IsRagdoll", false)
end)
elseif v.Parent.Name == Player.Name and config.LaunchTeammates == false then
if v.Parent.Name == Player.Name then
v.Parent:SetAttribute("IsRagdoll", true)
v.Parent.Torso.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Parent.HumanoidRootPart.Position).Unit *- config.SplashPressure
task.wait()
task.delay(0.01 * config.SplashPressure / 2,function()
v.Parent:SetAttribute("IsRagdoll", false)
end)
end
end
if not (v.Parent.Name == Player.Name) then
if v.Parent:FindFirstChild("Humanoid") and not damagedHums[v.Parent.Humanoid] and v.Name == "HumanoidRootPart" then
v.Parent.Humanoid:TakeDamage(config.SplashDamage)
damagedHums[v.Parent.Humanoid] = true
if v.Parent.Humanoid.Health <= 0 then
v.Parent.HumanoidRootPart.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Parent.HumanoidRootPart.Position).Unit *- config.SplashPressure
end
elseif v:HasTag("Prop") and not v.Parent:FindFirstChild("Humanoid") then
v.AssemblyLinearVelocity = (Explosion.OuterShell.Position - v.Position).Unit *- config.SplashPressure / 10
v.AssemblyAngularVelocity = Vector3.new(math.random(0, 45), math.random(0, 45), math.random(0, 45))
end
end
end
wait(0.25)
Explosion:Destroy()
end
Ok so it doesnt damage my player anymore, but still damages other players
So you want it to only give damage to NPCs ?
change
to
if v.Parent.Name ~= Player.Name and not game.Players:GetPlayerFromCharacter(v.Parent) then
Ok so, the other players no longer get damaged. however, when the launchteammates is set to true, it doesnt actually launch the players. I might just make it so that your teammates dont go flying, as it would be a bit annoying, so thank you so much!!
The instigator of the explosion will always be a player, so regardless of whether or not the instigator is excluded in the collision detection, the second clause of your if-statement will fail it. Therefore, you can remove:
v.Parent.Name ~= Player.Name
cheers man, this was very helpful lol