How to damage a player

Hello, there

I am working on my game, and I need players to get damaged the closer they are to the lightning bolt. I am using the v1.1 Lightning Beam.

Link: [Effect] v1.1 Lightning Beams: Seamless, smooth and procedurally animated with beam-like properties

I have customized the script in to my needs, but I need a script which would damage players, the closer they are to the sudden lightning bolt, which is really rapid. I really need assistance, as soon as possible.

Any help would be appritated!

Meant2Win

2 Likes

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.

2 Likes

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!

1 Like

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.

1 Like

I would rather use the first suggestion

1 Like

I meant the second one, lol sorry for the confusion

1 Like

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.

1 Like

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)

1 Like

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

7abe3a730632de527d28d98d8b797343

2 Likes

But right now, I just want to make the damage script

1 Like

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.

1 Like

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

1 Like

Thanks, will try that and get back to you.

1 Like

Yes, but the problem is that. I’ve tried that and it doesn’t work

1 Like

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. :slightly_smiling_face:

3 Likes

I can’t really help you then, since that’s about as simple as Roblox scripting gets.

1 Like

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.