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
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
script.Parent.Touched:Connect(function(hit) -- runs if part is touched local humanoid = hit.Parnet:FindFirstChildWhichIsA("Humanoid") -- locates humanoid if humanoid then -- checks if the thing that touched the part is a player humanoid.Health = humanoid.Health - 5 -- damages the player end 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:
game:GetService("Players").PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Health -= 5 end) 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
script.Parent.Touched:Connect(function(hit) local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid") if Humanoid then Humanoid:TakeDamage(5) end 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.