You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I am trying to make a mine that can be throw and detonated from a distance -
What is the issue? Include screenshots / videos if possible!
Multiple explosion from before keep appearing, its supposed to be one explosion. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I already tried making the explosion when you equip it, but it does a thousand damage when touched by explosion.
script.Parent.Equipped:Connect(function()
local CanDamage = true
local MAX_DAMAGE = 75
local MIN_DAMAGE = 25
local Explosion = Instance.new("Explosion")
Explosion.DestroyJointRadiusPercent = 0
Explosion.BlastRadius = 5
Explosion.BlastPressure = 50000
script.Parent.TriggerEvent.OnServerEvent:Connect(function(Player, EndPosition)
script.Parent.Handle.Transparency = 1
local Mine = game.ReplicatedStorage.ClonedInstances.SubspaceDetonatorMine:Clone()
Mine.Parent = workspace
Mine.Position = script.Parent.Handle.Position
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = (EndPosition - script.Parent.Parent:WaitForChild("HumanoidRootPart").Position).Unit * 75
BodyVelocity.Parent = Mine
wait(0.1)
BodyVelocity:Destroy()
wait(0.2)
Explosion.Position = Mine.Position
script.Parent.Handle.Touched:Connect(function()
Mine.Anchored = true
end)
script.Parent.DetonateEvent.OnServerEvent:Connect(function()
Explosion.Parent = workspace
local hitlist = {}
Mine:Destroy()
Explosion.Hit:Connect(function(HitPart, distance)
local Humanoid = HitPart.Parent:FindFirstChild("Humanoid")
if Humanoid and not table.find(hitlist, Humanoid) then
table.insert(hitlist, Humanoid)
local Initialdamage = (1 - distance / Explosion.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE
local damage = math.floor(Initialdamage)
print(damage)
Humanoid:TakeDamage(damage)
end
end)
end)
end)
end)
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
an example Lua code block
Local Script for the tool
local CanFire = true
local MinePlaced = false
local Player = game.Players.LocalPlayer
local Cooldown = 3
script.Parent.Equipped:Connect(function(mouse)
script.Parent.Activated:Connect(function()
if CanFire == true then
CanFire = false
MinePlaced = true
local EndPosition = mouse.Hit.Position
script.Parent.TriggerEvent:FireServer(EndPosition)
end
end)
end)
script.Parent.Equipped:Connect(function(mouse)
mouse.Button2Down:Connect(function()
if MinePlaced == true then
MinePlaced = false
script.Parent.DetonateEvent:FireServer()
wait(Cooldown)
CanFire = true
end
end)
end)
Server script for the tool
script.Parent.Equipped:Connect(function()
local CanDamage = true
local MAX_DAMAGE = 75
local MIN_DAMAGE = 25
script.Parent.TriggerEvent.OnServerEvent:Connect(function(Player, EndPosition)
local Explosion = Instance.new("Explosion")
Explosion.DestroyJointRadiusPercent = 0
Explosion.BlastRadius = 5
Explosion.BlastPressure = 50000
script.Parent.Handle.Transparency = 1
local Mine = game.ReplicatedStorage.ClonedInstances.SubspaceDetonatorMine:Clone()
Mine.Parent = workspace
Mine.Position = script.Parent.Handle.Position
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = (EndPosition - script.Parent.Parent:WaitForChild("HumanoidRootPart").Position).Unit * 75
BodyVelocity.Parent = Mine
wait(0.1)
BodyVelocity:Destroy()
wait(0.2)
Explosion.Position = Mine.Position
script.Parent.Handle.Touched:Connect(function()
Mine.Anchored = true
end)
script.Parent.DetonateEvent.OnServerEvent:Connect(function()
Explosion.Parent = workspace
local hitlist = {}
Mine:Destroy()
Explosion.Hit:Connect(function(HitPart, distance)
local Humanoid = HitPart.Parent:FindFirstChild("Humanoid")
if Humanoid and not table.find(hitlist, Humanoid) then
table.insert(hitlist, Humanoid)
local Initialdamage = (1 - distance / Explosion.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE
local damage = math.floor(Initialdamage)
print(damage)
Humanoid:TakeDamage(damage)
end
end)
end)
end)
end)
Please give suggestions, also mind that I cannot test any suggestions fast, because I will be travelling somewhere. Thank you.