Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't this script work?

Ok so I have tried to change the script so it would work and I have tried putting it into teams. Here is the script:

01 local playerStats = {} --this keeps a list of the stats for each player that enters the game

02

03

04

05 game.Players.PlayerAdded:connect(function(player)

06

07 local leaderstats = Instance.new("Model", player)

08

09 leaderstats.Name = "leaderstats"

10

11 game.Players.PlayerAdded:connect(function(player)

12

13 local leaderstats = Instance.new("Model", player)

14

15 leaderstats.Name = "leaderstats"

16

17

18

19 local money = Instance.new("IntValue", leaderstats) --We instance a new IntValue as a child of 'leaderstats'

20

21 money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game.

22

23 money.Value = 0 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)

24

25 end)

26

27 local money = Instance.new("IntValue", leaderstats)

28

29 money.Name = "Money"

30

31 money.Value = 0

32

33

34

35 stats[player] = leaderstats

36

37 end)

38

39

40

41 while true do --infinite loop

42

43 for player, stats in ipairs(playerStats) do --loops through each player => stat pair in the table

44

45 players.Money.Value = stats.Money.Value + 1

46

47 end

48

49 wait(5)

50

51 end

52

53 function CheckTeams(player)

54

55 if player.TeamColor == BrickColor.new("Bright red") then

56

57 player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1

58

59 end

60

61 end

Please help, I don't know what's wrong (yes I do have a team that is brick colour ''Bright red'' so it's not because it's for the wrong team.)

1 comment

0

Code Block your script. Click the Blue circle w/ "Lua" inside. Then paste your script between the squiggly lines "~~~~".

1 answer

game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("Model")
     leaderstats.Name = "leaderstats"
     leaderstats.Parent = player
 
     local money = Instance.new("IntValue") --We create a new IntValue
     money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game.
     money.Value = 0 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
     money.Parent = leaderstats -- Set the money object as a child of the leaderstats object.
 end)

That creates it, here is the loop

colour = Instance.new("BrickColor")
colour.Value = ("Bright red")
while wait(5) do 
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") and Player.TeamColor == colour then
            Player.leaderstats.Money.Value = playerLeaderstats[player]["Money"]
        end
    end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.