I’m developing a damage system for parts, but no idea how i’ll do it. I’d prefer not to use AI
local health = script.Parent:FindFirstChild(“PartHealth”) – this is an IntValue, likely going to be
local weld = script.Parent:(((find the weld)))
local bullet = (((find the bullet, i already have a specific name, just not sure how to detect and find what is hitting the part)))
local bulletdmg = (((get an intvalue within the bullet, some calibers like 9mm will be say, 15, tank rounds would be 300-700)))
(((bullet hitting will lower the health, when health goes to or under 0, the weld gets destroyed so the part falls onto the floor.)))
Is this possible what i’m trying to do?
--ServerScript in the destructible part
local part = script.Parent
local health = part:FindFirstChild("PartHealth")
local weld = part:FindFirstChildWhichIsA("Weld")
part.Touched:Connect(function(hit)
local bullet = hit:FindFirstChild("BulletDamage")
if bullet and health then
health.Value -= bullet.Value
if health.Value <= 0 and weld then
weld:Destroy()
end
hit:Destroy()
end
end)
Raycast
--ServerScript in the weapon or projectile system
local dmg = 25
local range = 500
local origin = muzzle.WorldPosition
local dir = muzzle.WorldCFrame.LookVector * range
local ray = workspace:Raycast(origin, dir)
if ray then
local hit = ray.Instance
local health = hit:FindFirstChild("PartHealth")
local weld = hit:FindFirstChildWhichIsA("Weld")
if health then
health.Value -= dmg
if health.Value <= 0 and weld then
weld:Destroy()
end
end
end
I’ll see how this works. I tried using AI but as always it never understands what I’m asking, although I did get some progress (health received damage.) I’ll edit this to fit the hierarchy of my weapons and the damaged parts
What I do is that the gun, when fired, does instance.new() and creates p, a projectile that hits wherever the mouse aims. If it hits the part, the script in the part will find the damage int, then subtract that from the health, once it is at or under 0, joints break. This is what I am trying to do but im too ADHD to try to focus and learn Luau, so I’m confused on what will work and what to do
fastcast is an easy solution.
i believe it uses object pooling, making it more efficient than instance.new. it also follows the behavior you’re looking for.
Useful, seems like a better alternative to using block projectiles. However, it’s “detectable” when it touches another part, right? I’ve never heard of these APIs/modules since I legit just started scripting maybe earlier this year.
I’m honestly only using it because I have some disorder that makes learning “slow” things hard, I’m actually getting it checked out soon lol, I started “making” Roblox games 5 years ago but I could never even learn scripting because it just wouldn’t click. You guys are saviors, I really don’t like using AI
I’m also creating a grand strategy game (like Europa Universalis) and I made some progress on it in terms of scripting but it’s so much to handle. I just need to know how to learn these things and I need “creativity” to come up with solutions to these kinds of problems
part projectiles can work when using roblox’s constraint system—align orientation / position. but thats for big things; maybe boulders. for small assets its definitely more effective to use raycasts.
fastcast can visualize and update a fake part along the route the bullet has taken, reducing performance costs.
I agree (assuming I have ADHD or something similar, my mother has a diagnosis of ADHD) because I love the idea of creating my own videogames ever since my favorite Roblox ones died out years ago. I’ve even tried to create a mod with the Source Engine (to no avail, what’d I know from a game engine from 21 years ago) I have spent years trying to learn it even though I know for a fact I know almost nothing about it besides syntax and UI
those could also use raycasts.
it largely depends on if you want the projectile to interact with the world. there would likely be edge cases with detection.
Oh, and for full context, I’m trying to create a large scale 40 player MMO shooter similar to Battlefield, so I really don’t know what’s efficient to use for destructible buildings and hundreds of bombs and bullets being shot. Would raycasts work for multiple bullets being fired by different weapons at once?
Also, should I use a big module/script for all of these or multiple scripts within the destructible parts? These maps are HUGE
yes.
raycasts are very performant. however, if they are long, they will take more memory. so fastcast breaks it up and tracks progress along the way. if it detects a hit it will start a callback where you can add the damage logic.
use collectionservice for multiple module setups. this will organize your code by avoiding the filter through childadded, giving you the instances as they are tagged or un-tagged.
I want to try this raycasting thing but how would it work?
Do I have a central script handling destruction or scripts in individual parts? What would it look like, just a simple hit detector that subtracts the health thats also in it?
Sidequestion: How can I improve on my scripting abilities and knowledge? I’m in high school but don’t know what electives could help me learn coding/computer science besides “Computers”