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

How do I change a stat of a person when someone enters my place?

Asked by 11 years ago

I want kane2100's lvl to change to 20000000 when he joins, but I dont think this will work, my script:

1game.Players.PlayerAdded:connect(function(player)
2if newplayer.Name == "kane2100" then
3game.Players.LocalPlayer.leaderstats.Lvl.Value = 20000000
4elseif game.Players.findFirstChild("kane2100").leaderstats.LvlValue == 20000000 then
5print("Already at that lvl")
6else
7print("Wrong Player")
8end
9end)

i'm probably not EVEN A INCH close to having this right.

1 answer

Log in to vote
0
Answered by 11 years ago

I'd recommend changing it in the same script that creates it. After it's created, check to see if the player's (should be a variable) name is equal to the string "kane2100". If so, then change the stat's (perhaps also a variable) Value to 2000000 instead of 0, or whatever you have it set to start at.

If you would like to go about it this way, let's give it some time to make sure that the leaderstats and the stat exist. Assuming that there aren't any other issues, and you don't need to make sure that they exist before this runs.. (Regular Script, not a LocalScript)

1game.Players.PlayerAdded:connect(function(np)
2if np.Name == "kane2100" then
3wait(2)
4np.leaderstats.Lvl.Value = 20000000
5end
6end)

But, to fix your code.. You have the variable 'player' for the player that joins, then tried to use 'newplayer', which does not exist. Then, you tried to use 'game.Players.LocalPlayer'. Afterwards, you have a pointless elseif that could break your script if kane2100 does not exist in the game at the time it runs. You can either do what I did, before, and just wait.. or you can have a loop keep waiting until it finds everything it needs.

1game.Players.PlayerAdded:connect(function(player)
2if player.Name == "kane2100" then
3repeat wait() until player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Lvl")
4player.leaderstats.Lvl.Value = 20000000
5end
6end)
0
Thanks so much! Operation_Meme 890 — 11y
0
Sure thing. grimm343 30 — 11y
Ad

Answer this question