Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there away to efficiently damage a player via server?

I'm trying to make a damaging system. So I need to figure out how to damage a specific player through the server because I've recently learned that damaging through the client is just stupid. So to test difference methods of damaging I'm trying to damage the player when they join the game. Here is one of my attempts below:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    local Humanoid = player.name
    Humanoid.Health = Humanoid.Health - 5
end)

I tried this because of the Humanoid.Health property. And I chose to use the players name as the humanoid because I read from an article that you can fetch the Humanoid by getting the players name.

So yeah, feel free to roast or lecture me below, it'll help out a lot.

1 answer

You can get the humanoid from the character, not the player name. Calling :TakeDamage on a humanoid damages them unless they have a force field.

player.Character.Humanoid:TakeDamage(5)

2 comments

0

I tested this out and it gives me an error that says "attempt to index nil with 'Humanoid'". Any thoughts? Thanks for trying to help out though.

0

Never mind I've found a different solution. Thank you so much for your help either way because I've learned something from this.

This discussion is preserved as it was. New answers, comments, and votes are closed.