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 10 years ago

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

game.Players.PlayerAdded:connect(function(player)
if newplayer.Name == "kane2100" then
game.Players.LocalPlayer.leaderstats.Lvl.Value = 20000000
elseif game.Players.findFirstChild("kane2100").leaderstats.LvlValue == 20000000 then
print("Already at that lvl")
else
print("Wrong Player")
end
end)

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

1 answer

Log in to vote
0
Answered by 10 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)

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

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.

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

Answer this question