local player = game:GetService("Players")
local plr2 = player.LocalPlayer.Character
game.Players.PlayerAdded:Connect(function(plr)
if script.Parent.Health <= 0 then
plr2.expStats.Exp.Value += 5
end
end)
first the enemy will clone to workspace, and after that
so i wanted to make when Local player kill Enemy it will give the player point to Local players leaderstats (the player who kiled the enemy)
first of all, why do you have the player variable (which is literally players, not player ), and then instead of using that variable, you do game.Players??
second of all, this will not work the way you want it to
i assume this is a server script, and LocalPlayer is not a thing inside server scripts
instead, you should just have a character variable that takes the player from the function:
local character = plr.Character
third of all, this will only run once, when a player joins, not when the player kills the enemy
essentially, if an enemy’s health is <= 0 at the same moment a player joins, the player will gain points without killing the enemy
you should use remote events for this, and give points to the player from server side
i don’t know how killing does its job on the client, but here’s an example script:
local tool = script.Parent
local event = game:GetService("ReplicatedStorage").RemoteEvent
tool.Activated:Connect(function()
event:FireServer()
end)
----- SERVER SIDE -----
local event = game:GetService("ReplicatedStorage").RemoteEvent
event.OnServerEvent:Connect(function(player)
-- handle killing
player.Exp.Value += 5 -- have an EXP IntValue inside the player, then add to that
end)