What's wrong with my scripts?

Hello people of Devforum! I’m trying to make an M1 script with a hitbox, which is parented to the player. I have two scripts, one of which is a local script located in StarterCharacterScripts. Here it is:

players = game:GetService("Players")
player = players.LocalPlayer
character = player.Character
humanoid = character:WaitForChild("HumanoidRootPart")
mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	local hitbox = script.Parent:WaitForChild("Hitbox")
	hitbox.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local personToKill = hit.Parent:FindFirstChild("Humanoid")
			if tostring(personToKill.Parent) ~= player.Name then
				print("person i want to kill: " .. tostring(personToKill.Parent))
				print("attacker's name: " .. player.Name)
				local victimName = tostring(personToKill.Parent)
				game.ReplicatedStorage.hit2:FireServer(victimName)
			end
		end
	end)
end)

The other is located in ServerScriptService, here is what the server script contains:

game.ReplicatedStorage.hit2.OnServerEvent:Connect(function(victimName)
	print("killed: " .. victimName.Name)
end)

For some odd reason, it’s transmitting my name instead of the name of the player I’m hitting. I added some prints that show what’s wrong. Can anyone explain what the problem is?

Remote events pass always pass the player as the first parameter (See Here). victimName is the player who is firing the remote event. Try this:

game.ReplicatedStorage.hit2.OnServerEvent:Connect(function(attacker, victimName)
	print("killed: " .. victimName.Name)
end)
2 Likes

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