Depends the lightning can just be an effect that does nothing but visual, but lets say its an “Strike” that strike and appears fast then you can just use Region3, Part or Magnitude but lets say we use Part as the Hitbox we can then spawn a Box on the position where it striked then check who touched the box, after you got the people that was “Striked” then you can do
local Damage = 10
Part.Touched:Connect(function(TouchedPart)
local Ancestor = TouchedPart.Parent
if Ancestor and Ancestor:FindFirstChild("Humanoid") then
Ancestor.Humanoid.Health -= Damage
end
end)
That’s just 1 of the example there’s alot of way to accomplish it.
No, the lightning is not a effect, they are literal parts. Shall I copy the code, and paste it in to my script(server script)? Thanks in advance!
Yes I know that but you have to think differently, Would you want to use 9999999 Parts as the same hitbox? Compare that to 1 Invisible Part that is used as your hitbox with the same size as the length of the lightning.
I would rather use the first suggestion
I meant the second one, lol sorry for the confusion
Anyways how game mostly does it is what I said but it still depends on how the lightning will work is it continuous(just strikes multiple times)? or does it linger(like it stays long on the map)? if its just a casual minecraft style ‘smite’ then above is a good example, thought region3 would be a better hitbox.
No, I want random strikes all over the map, random but has a chance of striking one of the players. Right now, it is continous strikes, I will fix that later, right now I want to focus on damaging the players.
robloxapp-20220308-1217325.wmv (286.6 KB)
Yea the above example is what I’ll use if I were to make that description of what you want, this is basically how it’s gonna work but in all of the lightning. Ignore the lightning ‘growing’ I just showed an example of the steps. The hitbox also doesn’t have to be the big it could just be a ground level of the hit position
But right now, I just want to make the damage script
Well to damage a player is
Player.Character.Humanoid.Health -= 5
so how will we find who got ‘hit’? or who that ‘player’ is
anyways what you need is a hitbox to find who got ‘hit’ which I described above and then alternate their current health.
You can either use Player.Character.Humanoid.Health -= Damage
as suggested or you can call the TakeDamage()
instance method on a humanoid instance, i.e;
humanoid:TakeDamage(10) --The humanoid's health is decreased by 10.
humanoid:TakeDamage(-10) --The humanoid's health is increased by 10.
https://developer.roblox.com/en-us/api-reference/function/Humanoid/TakeDamage
Thanks, will try that and get back to you.
Yes, but the problem is that. I’ve tried that and it doesn’t work
You could also use TakeDamage
, it might be cleaner:
local Damage = 10
Part.Touched:Connect(function(TouchedPart)
local Ancestor = TouchedPart.Parent
if Ancestor and Ancestor:FindFirstChild("Humanoid") then
Ancestor.Humanoid:TakeDamage(Damage)
end
end)
Just cleaned up a bit.
I can’t really help you then, since that’s about as simple as Roblox scripting gets.
And can we implement hitbox in our scenerio?
Oh, I will keep on, trying. But
Thanks for your time!
Yes you can apply hitbox on all the Thunder strike if you know how to work with loops.
I’m really confused. These other suggestions people have given you should have helped.