I’m creating a game and I need some help on creating a weapon system. I’ve never been experienced in creating weapons but now I’ve tried and over the past few months, 13 weapons have been created! Most of them worked but they had some flaws and about 1/4th of them had issues, but that’s not what I’ll be talking about on this post. I want to know how I can make a organized and easy to navigate weapon system.
My current ideas is to have all of the weapons stats, (damage, weight / affectsSpeed?, abilities, cooldown, etc…), passives, and abilities inside of one module, with the module also having functions for the weapon that the weapon can access through a server script.
Whenever I have an issue with my bombs, it may be caused by the base code but the issue with that is that if I have a problem with that base code then if I make a change to fix it then I need to change EVERY, SINGLE, BOMB that also has that base code and considering that me and my developing partner / friend have come up with 57 weapons and counting, and so it will be very hard to navigate and manage this.
There’s also other weapons that I will also need to manage like swords, slingshots, superballs, and launchers that I will have to navigate through which will make this harder.
This is the current hierarchy of children of the average bomb.
This is the current script for the average bomb (Classic Bomb).
local tool = script.Parent
local bombHandle = tool:WaitForChild("Handle")
local ActivateBombRemote = script.Parent:WaitForChild("ActivateBomb")
local tickSound = Instance.new("Sound")
tickSound.SoundId = "rbxasset://sounds\\clickfast.wav"
tickSound.Parent = tool
local explosionSound = Instance.new("Sound")
explosionSound.SoundId = "rbxasset://sounds\\Rocket shot.wav"
explosionSound.Parent = tool
local blastRegion3L = 10/2 -- The Length of the Blast (Dividing all of the dimensions by 2 so that the region3 is not twice its size after making its size relative to the position)
local blastRegion3W = 10/2 -- The Width of the Blast
local blastRegion3H = 10/2 -- The Maximum height of the region3
local baseDamage = 25
function explosionParticles(bomb)
local explosionClone = bombHandle.Explosion:Clone()
explosionClone.Parent = bomb
explosionClone.Enabled = true
return explosionClone
end
function explode(bomb, user)
for i = 1, 3 do task.wait(1)
tickSound:Play()
end
task.wait(1)
bomb.Anchored = true -- Anchores the bomb so that it doesn't go elsewhere due to the explosion.
local explosionParticle = explosionParticles(bomb)
local explosionSoundClone = explosionSound:Clone()
explosionSoundClone.Parent = bomb
explosionSoundClone:Play()
bomb.Transparency = 1
local region3 = Region3.new(
bomb.Position - Vector3.new(blastRegion3L, blastRegion3H, blastRegion3W),
bomb.Position + Vector3.new(blastRegion3L, blastRegion3H, blastRegion3W) -- Makes a square that is 5x5 long and wide, and 10 studs high (hence the 1 to 10)
) -- Creates a region3 that destroys any parts in the explosions radius.
local region3Visual = Instance.new("Part") -- The visualized part for the region3.
region3Visual.Name = "blastRadiousVisual"
region3Visual.CanCollide = false
region3Visual.Size = region3.Size
region3Visual.CFrame = region3.CFrame
region3Visual.Anchored = true
region3Visual.Transparency = .5
region3Visual.Parent = workspace.Terrain
region3Visual.BrickColor = BrickColor.new("Persimmon")
local explosion = Instance.new("Explosion") -- The explosion instance
explosion.Parent = bomb
explosion.Position = bomb.Position
explosion.BlastRadius = 0
explosion.DestroyJointRadiusPercent = 0
explosion.BlastPressure = 900000
explosion.BlastRadius = blastRegion3L
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = {tool, tool.Handle, region3Visual}
local parts = workspace:GetPartBoundsInBox(region3.CFrame, region3.Size, overlapParams)
explosion.Hit:Connect(function(Part)
if Part.Name == "HumanoidRootPart" then
local character = Part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player and player.Team ~= user.Team then
character:FindFirstChildOfClass("Humanoid"):TakeDamage(baseDamage)
if character:FindFirstChildOfClass("Humanoid").Health == 0 then
user.leaderstats.Kills.Value += 1
end
elseif player ~= user and player.Neutral == true then
character:FindFirstChildOfClass("Humanoid"):TakeDamage(baseDamage)
if character:FindFirstChildOfClass("Humanoid").Health == 0 then
user.leaderstats.Kills.Value += 1
end
end
end
end)
for i, v in pairs(parts) do
if v.Name == "Brick" then
v.Anchored = false
v.CanTouch = false
v.BrickColor = user.TeamColor
for i, constraint in pairs(v:GetChildren()) do
if constraint:IsA("Snap") or constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
constraint:Destroy()
end
end
task.delay(2, game.Destroy, v)
end
if v.Name == "GameBrick" then v.Name = "TaggedGameBrick" -- TaggedGameBricks are GameBricks in the game that have been effected by the bomb, while regular Bricks are just bricks you can destroy by default.
v.Anchored = false
v.CanTouch = false
user.leaderstats.Bricks.Value += 1 -- The total bricks the player has broken throughout the round.
user["T. Bricks"].Value += 1 -- The total bricks that the player has destroyed throughout there playtime
user.leaderstats.Studs.Value += .1 -- Increases the players currency (Studs) by 0.1.
v.BrickColor = user.TeamColor -- Changes the taggedBricks color to the local players team color to show that they have broken the part.
task.delay(2, game.Destroy, v) -- later deletes the part.
end
end
task.delay(3, game.Destroy, bomb)
task.delay(3, game.Destroy, region3Visual)
task.wait(2)
explosionParticle.Enabled = false -- Disables the explosion particles.
end
ActivateBombRemote.OnServerEvent:Connect(function(user) -- This is the function that makes the bomb go off, which connects the ActivateBomb Remote Event to this script after it gets activated by the local script.
local bombClone = bombHandle:Clone()
bombClone.Parent = game.Workspace
bombClone.CanCollide = true
bombClone.CFrame = bombHandle.CFrame * CFrame.new(0, 2, 2)
explode(bombClone, user)
end)
i