So I have a rocketeer tower in my tower defense game, but, It attacks like a normal tower. What could I add to my tower handler script to make explosion damage?
if newTower.Name == "Rocketeer" then
--do stuff
end
So I have a rocketeer tower in my tower defense game, but, It attacks like a normal tower. What could I add to my tower handler script to make explosion damage?
if newTower.Name == "Rocketeer" then
--do stuff
end
You can do this to create an explosion to damage players
local playersHit = {} -- detect if player has already been hit
local Explosion = Instance.new("Explosion")
Explosion.BlastRadius = 4 -- change this for range
Explosion.ExplosionType = Enum.ExplosionType.NoCraters
Explosion.BlastPressure = 0 -- flinging value
Explosion.Position = newTower.Position -- change this if you want a projectile to explode
Explosion.DestroyJointRadiusPercent = 0 -- change to 1 if it kills players instantly
Explosion.Hit:Connect(function(hit) -- detect parts hit by explosion
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not table.find(playersHit, player) then
player.Character.Humanoid:TakeDamage(10) -- change damage
table.insert(playersHit, player)
end
end)
Explosion.Parent = newTower -- or workspace or projectile
would it work on npcs?
limit
i dont think you need playersHit variable
cuz hes doing an tower deffense game wont really matter if npc got hitten or no
Do this instead
local charactersHit = {}
local Explosion = Instance.new("Explosion")
Explosion.BlastRadius = 4 -- change this for range
Explosion.ExplosionType = Enum.ExplosionType.NoCraters
Explosion.BlastPressure = 0 -- flinging value
Explosion.Position = newTower.Position -- change this if you want a projectile to explode
Explosion.DestroyJointRadiusPercent = 0 -- change to 1 if it kills players instantly
Explosion.Hit:Connect(function(hit) -- detect parts hit by explosion
local character = hit.Parent
if character:FindFirstChildOfClass("Humanoid") and not table.find(charactersHit, character) then
character.Humanoid:TakeDamage(10) -- change damage
table.insert(charactersHit, character)
end
end)
Explosion.Parent = newTower -- or workspace or projectile
It will account for every single body base part in the character hit by the explosion, thus dealing damage multiple times
then you gotta remove the player from the table after a slightly seconds cuz an tower is obv shooting more than 1 time so the second time it wont damage
You can just put it in seperate functions or scripts, if it’s not possible then use table.clear(charactersHit)
how would i make it to the target position? it seems to be saying attempt to index nil with 'Position'
whenever i try.
The tower seems to be a model, you can use Explosion.Position = newTower:GetPivot().Position
(won’t work if tower isn’t a model or a BasePart)
Also use the code with charactersHit if you want the code to detect NPCs as well
it works now! just needs alittle more configuring im sure i can solve.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.