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!
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
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