Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get a player's character and humanoid from a server-side script?

Asked by 3 years ago

I've searched through so many devforum posts yet I have not found an answer. I need to find the character to get the humanoid so when a player activates an admin command to kill a player, the player stated is killed. Here's my script.

Once again, it's a server script.

01commands.kill = function(sender, arguments)
02 
03    print("Kill command fired by "..sender.Name)
04    local plrToKill = arguments[1]
05    if plrToKill == "me" then
06        plrToKill = string.lower(sender.Name)
07        arguments[1] = plrToKill
08    end
09    local plrChar = game.Workspace:FindFirstChild(plrToKill)
10 
11    if plrToKill then
12        local plr = findPlayer(plrToKill)
13 
14        if plr then
15            local plrHum = nil
View all 29 lines...

Everything else works fine, but I get an error saying "attempt to index nil with 'Humanoid' which I find very confusing. Any help is greatly appreciated.

0
Print ''arguments[1]'' and tell me the result, I think I know the issue Cirillix 110 — 3y
0
If 'arguments[1]' is "me", then you've changed the username to all lowercase. Clearly, your username will not match that Ziffixture 6913 — 3y
0
Furthermore, you're trying to make a reference to 'Humanoid.Health', which is something you cannot do; adjusting 'Health' will only adjust the variable Ziffixture 6913 — 3y
0
When you refer to a property, you read from it. Ziffixture 6913 — 3y
View all comments (3 more)
0
And why not just set 'Humanoid.Health' to zero? Ziffixture 6913 — 3y
0
And why search Workspace when you can just look into Player's directly? Ziffixture 6913 — 3y
0
You can use a remoteevent on the server to get the player and players character. Oliver_Bocch 32 — 3y

Answer this question