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

Adding a player's name to a table when they die through remoteEvents?

What I'm trying to do is when a player dies, their name is added to a table, I know how to add a string to a table, but not how to use remoteEvents to pass the player's name.

--Inside ServerScriptStorage
local deadPlayers = {}
local event = Instance.new("RemoteEvent")
event.Parent = game.Workspace
event.Name = "MyServerEvent"
event.OnServerEvent:connect(function() 
	table.insert(deadPlayers, --[===[Not sure what to add here]===])
end)

--Inside StarterGui/StarterPack as a local script
game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			game.Workspace.MyServerEvent:FireServer()[===[Not sure what to add here in order to send the player's name.]===]
		end)
	end)
end)

1 answer

--Inside ServerScriptStorage
local deadPlayers = {}
local event = Instance.new("RemoteEvent")
event.Parent = game.Workspace
event.Name = "MyServerEvent"
event.OnServerEvent:connect(function(player) 
    table.insert(deadPlayers,#deadPlayers+1,player.Name)
end)

--Inside StarterGui/StarterPack as a local script
game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            game.Workspace.MyServerEvent:FireServer()
        end)
    end)
end)

The above will(maybe) do want you want, but let me give you some knowledge of remote events.

--localScript--
event = game.ReplicatedStorage:WaitForChild("ShortName")
wait(3)
event:FireServer("Argument1",true)
--server--
event = Instance.new("RemoteEvent",game.ReplicatedStorage)
event.Name = "ShortName"

event.OnServerEvent:connect(function(player,message,DaBool)
	--the first argument is always the player
	--the others can be anything you want
	print(player.Name.." says "..message)
	if DaBool then
		print("True!")
	else print("Why did you send over false ;(")
	end
--[[ will print:
Player1 says Argument1
True!
--]]
end)

So that's how you send things through RemoteEvents, leave a comment if you want something clarified!

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