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

How would I find the local player in a server script?

I am making a script, that every time the npc dies, the player gets +10 coins to their leader stats named "coins". I use the player added function but it only adds plus 10 once. then when the npc health value reaches 0 again, it doesn't add +10. Please help!

local health = script.Parent --script is in a health value of my npc

health.Changed:Connect(function() if health.Value <= 0 then local currentposition = script.Parent.Parent.HumanoidRootPart.CFrame health.Value = 10 script.Parent.Parent.HumanoidRootPart.CFrame = turtlerespawn.CFrame

	--Utter confusion--

	game.Players.PlayerAdded:Connect(function(plr)
		local player = plr
		print(player.Name)
		print("Plus 10")
		player.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 10
	end)
	wait(5)
	script.Parent.Parent.HumanoidRootPart.CFrame = currentposition
end

	----------------------------------------------------------------------------------------

end)

1 comment

0

the coded part is the part that i'm trying to find the local player in.

1 answer

✓ Accepted answer

if you are killing the npc, make something that will tag the player that hits the npc like in the default sword. If you want assists or damage requirements, make a number that shows the dmg done instead of just tagging the player.

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