Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

when you get 1 kill it dosent print the code in the output?

Asked by 2 years ago
game.Players.PlayerAdded:Connect(function(kills)
    if kills.Parent.Humanoid.leaderstats.Kills == 1 then
        print("hi")
    end
end)

2 answers

Log in to vote
0
Answered by 2 years ago

If you are using a number value then you have to reference the value.

game.Players.PlayerAdded:Connect(function(kills)
    if kills.Parent.Humanoid.leaderstats.Kills.Value == 1 then -- If you are using number value then "Kills" will have a value property
        print("hi")
    end
end)
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

The PlayerAdded event has a parameter known as the player that was added to the Players service. You can look at the API of the player here.

I can't really help you because I don't know your hierarchy, for example, the location of your leaderstats. I got confused because the leaderstats has to always be in PlayerObject to be visible and not the humanoid of a Character.

For now, I'm just gonna locate the leaderstats based on your code.

SCRIPT

game.Players.PlayerAdded:Connect(function(player)
   local Kills = player.Character.Humanoid.leaderstats.Kills
   Kills:GetPropertyChangedSignal:Connect(function()
      if Kills.Value == 1 then
         print("hi")
      end
   end)
end)

Make sure it's a Script and not a LocalScript. If it was a LocalScript, it can be exploited badly.

EXPLANATION

Line 1 Connecting a function to a PlayerAdded event.
Line 2 Created a variable for the Kills IntValue.
Line 3 Connecting a function to the GetPropertyChangedSignal event.
Line 4 An if statement to check if the player has 1 kill.
Line 5 Printing "Hi".

You should put more effort into your question and make it more descriptive. To make a good question, you can check here.

Answer this question