I'm having problems with Player Object

Hi, i’ve been trying to fix this but i’m tired after hours and hours i’ve been scripting, i would like some help!

So it’s not changing the Exp, that’s the problem, there’s nothing in the console.

Server:

if Humanoid.Health > 0 then
					
					if Humanoid.Health == Humanoid.MaxHealth then
						Humanoid.Died:Connect(function()
							game.ReplicatedStorage.AddPoints:FireClient(game:GetService("Players")[Tool.Parent.Name], Humanoid.Points.Value)
						end)
					end

Local:

script.Parent.OnClientEvent:Connect(function(Player, Points)
	Player.leaderstats.Exp.Value += Points
end)

You should probably change the points on the server

You cant update the data locally

if Humanoid.Health > 0 then				
	if Humanoid.Health == Humanoid.MaxHealth then
		Humanoid.Died:Connect(function()
			local Player = game:GetService("Players")[Tool.Parent.Name]
 			Player.leaderstats.Exp.Value += Humanoid.Points.Value
		end)
	end
end

That’s because you update it locally and not on the server.
That value won’t replicate to the server (the server doesn’t know if it was updated or not since it doesn’t replicate).

Do what the ones above me said: Do it on the server-side.

1 Like

Still not working, you can’t get the local player in a server script.

if u have the name or the character you can easily get the player

because how are you firing the client then?

Maybe make it something like;

if Humanoid.Health > 0 then
					
					if Humanoid.Health == Humanoid.MaxHealth then
						Humanoid.Died:Connect(function()
							game:GetService("Players"):FindFirstChild([Tool.Parent.Name]).leaderstats.Exp.Value += Humanoid.Points.Value
						end)
					end

Not sure if this will make it work but it’s worth a try.

When using FireClient, the first argument in the client call is automatically the player itself. No need to provide it if no needed. In your case, add another param for the player.

Plus, it’s always better to update stats on the server.

On a server script :
If you want to award the killed player -

game.Players.PlayerAdded:Connect(function(Player)
  Player.CharacterAdded:Connect(function(Char)
       Char:WaitForChild("Humanoid").Died:Connect(function)
         --do stuff here
       end)
   end)
end)

If you want to reward the killer :

game.Players.PlayerAdded:Connect(function(Player)
  Player.CharacterAdded:Connect(function(Char)
       Char:WaitForChild("Humanoid").Died:Connect(function)
         local tag = Char:WaitForChild("Humanoid"):findFirstChild("creator") 
           if tag ~= nil then 
	     	    if tag.Value ~= nil then  
                    local Leaderstats = tag.Value:findFirstChild("leaderstats") 
			        if Leaderstats ~= nil then 
                       Leaderstats.Kills.Value += 1
                    end
                end
           end
       end)
   end)
end)
  1. Your LocalScript is in ReplicatedStorage, meaning it will not run at all.
  2. OnClientEvent does not give you Player object, it will only give you the arguments after that.
  3. You must change leaderstats on the server so that all the players would see the change.
  4. Why do you have Humanoid.Died event behind 2 different health checks?
1 Like

I’ve fixed it, thanks to everyone for helping!

image
Server:

script.Parent.OnServerEvent:Connect(function(plr, Points)
	plr.leaderstats.Exp.Value += Points
end)

Local:

Tool.Activated:Connect(function(plr)
	Tool.AddPoints:FireServer(100)
end)
1 Like