I want the player to get 5hp damage using the serverscript, is there a way it could be done?
Many Thanks, badcarftyt
The easiest way is by using
1 | Humanoid:TakeDamage(int) |
Also using Humanoid:TakeDamage should be used in serverscripts anyway. Here's more info about it. https://developer.roblox.com/en-us/api-reference/function/Humanoid/TakeDamage NEVER USE HUMANOID:TAKEDAMAGE ON CLIENT SCRIPTS!!
Hello, I don't know if you are trying to make the player take damage via touching a part or just a script. So I'll write a script showing how to damage a player with a part
1 | script.Parent.Touched:Connect( function (hit) -- runs if part is touched |
2 | local humanoid = hit.Parnet:FindFirstChildWhichIsA( "Humanoid" ) -- locates humanoid |
3 | if humanoid then -- checks if the thing that touched the part is a player |
4 | humanoid.Health = humanoid.Health - 5 -- damages the player |
5 | end |
6 | end ) |
This above is a way to damage a player via server script that has a part or object as a parent. Maybe you could do something with Humanoid:TakeDamage()
Thanks for your time. - Zeta
TakeDamage is used for damaging, but if a player has ForceField on, it will not damage. Instead, setting the humanoid health directly will not care if player have forcefield on, and damage.
Also they are supposed to do in ServerScripts, example script:
1 | game:GetService( "Players" ).PlayerAdded:Connect( function (player) |
2 | player.CharacterAdded:Connect( function (character) |
3 | character:WaitForChild( "Humanoid" ).Health - = 5 |
4 | end ) |
5 | end ) |
(This script makes any joined person damages 5)
oh by the way, heres a script to damage a person when touched a part, but with TakeDamage, so if the person have forcefield, it won't damage
1 | script.Parent.Touched:Connect( function (hit) |
2 | local Humanoid = hit.Parent:FindFirstChildWhichIsA( "Humanoid" ) |
3 |
4 | if Humanoid then |
5 | Humanoid:TakeDamage( 5 ) |
6 | end |
7 | end |
So you will use RemoteEvent if its from a client. I want you to learn how to use it that's why I didn't show the code use the link to understand it.