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

How do you get Humanoid on a Server Script?

Asked by 2 years ago

Hello! I want to know how to get Humanoid on a Server Script.

I have an alive IntValue on the Values folder located in Workspace.

I am making a round system game. Whenever a player enters the round, the alive value increases by +1.

When the alive value = 0, the round ends.

I managed to do that, but now I'm stuck with detecting the humanoid.

I do not want to use any loops or playeradded codes because it wouldn't work.

Can somebody help me? Here's the code:

local function SubtractAliveCount(player)
    local Alive = game.Workspace.Values.Alive
    Alive.Value = Alive.Value - 1
end

Humanoid.OnDied:Connect(SubtractAliveCount)

Thanks!

0
pov: u believe that the server is a player greatneil80 2647 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

This can be solved by accessing the humanoid from the client, then using RemoteEvents to pass the information to the Server, instead of doing game.Players.PlayerAdded or Loops. That method is actually a unique way to grab the humanoid on the server. This was not tested by me, just said through pure knowledge. Let's show an example of this taking action:

Client script:

local player = game.Player.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
wait(0.5)
RemoteEvent:FireServer(player)

Then connect to it in the server and do whatever. But in your case, it probably won't work. But I hope this helps you understand another way to do it besides your typical game.Players.PlayerAdded or Loop methods. Also, this is how to connect it to the server: Server example of connecting:

local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(player)

end)

Never mind, by default it already passes the player value to tell which player fired the event. Ignore this part. Well, this took a long time to make. Bye, and I hope this helps! :D

0
Thank you for your effort, but the 1st block of script is only for LocalScript, since you can't access player by doing game.Players.LocalPlayer. But, I appreciate it! TestAccount_PinkLeaf 14 — 2y
0
you can most DEFINITELY access the player by using game.Players.LocalPlayer in a local script. Antelear 185 — 2y
0
Yea, sorry for the game.Player, a typo Finty_james 269 — 2y
0
Also the one below the client script is meant for a LocalScript, you know that right? Just like @Opalmime said Finty_james 269 — 2y
View all comments (2 more)
0
I mean the text that says "Client script Finty_james 269 — 2y
0
Also what you want is easy. Get every player by :GetPlayers. Check if each and every player has a model in the workspace with the same name. Then check if they are in the map range like putting a invisble and no colliding box and checking if the player is currently touching it. Thne for every player that is touching, increase the value + 1. When the round timer ends, just set it to zero. Easy! Finty_james 269 — 2y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago
local function PlayerAdded(player)
    player.CharacterAdded:Connect(function(character)
        local Humanoid = character:WaitForChild("Humanoid")

        Humanoid.Died:Connect(function()
            print(player.Name .. "died!!!")
        end)
    end)
end

game:GetService("Players").PlayerAdded:Connect(PlayerAdded)

-- This extra code will make sure PlayerAdded function works

for _, player in pairs(game:GetService("Players"):GetPlayers()) do
    PlayerAdded(player)
end
0
Self explanatory, but the print will be fired once a player died in the game, so hope you learn something new Xapelize 2658 — 2y

Answer this question