How do I get the local player in a serverscript?

Im trying to send a remote event to the client when someone is killed but how do I get the local player when it happens?

local Bullet = script.Parent
local NearbyBulletSound = Bullet:WaitForChild('NearbyBulletSound')
local Players = game:GetService("Players")
local player = Players.. --What do i put here?

local Damage = Bullet:WaitForChild("Damage")

local Damaged = false

Bullet.Touched:Connect(function(hit)

	local CharHum = hit.Parent:FindFirstChildOfClass("Humanoid")

	if hit and CharHum and CharHum.Health > 0 then
		game.SoundService.DingSound:Play()

		player.folder.lastkilled.Value = hit.Parent.Name
		game.ReplicatedStorage.Killed:FireClient(player)
		
		CharHum.Health = CharHum.Health - Damage.Value
		NearbyBulletSound:Play()


	end
	wait(0.1)
	Bullet:Destroy()
end)

while wait(1.5) do
	Bullet:Destroy()
end


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

If you are able to get the character of the player, then you can use:

local player = game:GetService("Players"):GetPlayerFromCharacter(character)
2 Likes

I dont have a character value? So where do i put it?

local character = CharHum.Parent

I think you mean the player that died and not the local player. The local player is only available on the client. But you can connect to the humanoid died event and send your event to the client there. Humanoid | Documentation - Roblox Creator Hub

that is the player who got hit

Im trying to make a pop up saying you killed so and so and not the player that died

The player that died will trigger the humanoid.Died event. At that time you will have all the info you need to send an event to the client.

Im not trying to send something to the player who died but the player who killed the person

Ok I understand you need the player that killed someone

Ok, im sorry for the miscommunication but will the Humanoid.Died event will do that?

Well, you can attach the name or userid or a reference of the player who fired the bullet to the bullet. Then in your script you can pull out the info and send it in a remote event to the client to pop up the gui to the correct player

im sorry but im new to coding so how would I pull out the info and then send it when the script that is firing the event is in the bullet

No it won’t do that. Just label each bullet with the firing players information

how would i get the players info, do i need to create a value to store it?

Where you prepare the bullet you can add an attribute called owner withe the userid of the player then in the script above you can read the owner from the bullet. Instance | Documentation - Roblox Creator Hub

Would I do it something like this?

	local owner = Instance.new("StringValue")
	owner.Name = "Owner"
	
	

Yea but I think the userid is a number so use a numbervalue

thanks but how would i get the user id?

In the script where you create the bullet you should know the player firing then parent the number value to the bullet