Remote Event not passing argument

I’m working on a kill feed for the classic linked sword.

When I try to pass the kill message from a local script to a script using a remote event, the script just prints the player’s name instead of the kill message. I don’t think it’s receiving the kill message.

StarterPlayer>StarterPlayerScripts>LocalScript

local player = game.Players.LocalPlayer

local function onCharacterAdded(char)
	local humanoid = char:WaitForChild("Humanoid")

	local function onDeath()
		local tag = humanoid:FindFirstChild('creator')

		if tag and tag.Value then
			local distance = (char.HumanoidRootPart.Position - tag.Value.Character.HumanoidRootPart.Position).Magnitude
			local rounded = math.round(distance * 10) / 10
			local DeathMSG = player.Name .. ' was killed by ' .. tag.Value.Name .. ' ' .. rounded .. ' studs away.'
			print(DeathMSG)
			game.ReplicatedStorage.KillFeedEvent:FireServer(DeathMSG)
		end
	end

	humanoid.Died:Connect(onDeath)
end

player.CharacterAdded:Connect(onCharacterAdded)

ServerScriptService>Script

game.ReplicatedStorage.KillFeedEvent.OnServerEvent:Connect(function(DeathMSG)
	print("RemoteEvent connected! Printing DeathMSG next.")
	print(DeathMSG)
end)

When you fire a remote event to the server, the first parameter is always the player who fired the remote event. To fix your script you just need to add a player variable before DeathMSG in the event connection.

1 Like

The first recieved parameter on the server end is the player who called it. Instead of function(DeathMSG), try function(Player, DeathMSG)

1 Like

Thanks, @txcIove and @SeargentAUS !
Adding the player variable in the connection fixed it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.