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

leaderstat values not being created?

Asked by 7 years ago

I'm working on a game that obviously has leaderstats and this script has been giving me issues and if anyone knows why it is loading the value "Trimmings" and "Mower" but not the value "Strength" into the leaderstats folder in studio, please do tell me how to fix it. Script:

01game.Players.PlayerAdded:connect(function(plr)
02    local ls = Instance.new('Folder')
03    ls.Name = 'leaderstats'
04    ls.Parent = plr
05 
06    local t = Instance.new('NumberValue')
07    t.Name = 'Trimmings'
08    t.Parent = ls
09 
10    local s = Instance.new('NumberValue')
11    s.Name = 'Strength'
12    s.Parent = ls
13    s.Value = 0
14 
15    local m = Instance.new('StringValue')
16    s.Name = 'Mower'
17    s.Parent = ls
18    s.Value = 'Mower'
19end)
0
I know, on the local m thing you then under put in s.name, parent and value put in m instead just a normal mistake. Nilsen84 1 — 7y
0
oops, didn't realize. that's a very foolish mistake Sonostor 17 — 7y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

Since you figured it out, you can also optimize this by using a dictionary!

01local players = game:GetService("Players")
02 
03local stats = {
04    ["Trimmings"] = {objectType = "NumberValue", defaultValue = 0};
05    ["Strength"] = {objectType = "NumberValue", defaultValue = 0};
06    ["Mower"] = {objectType = "StringValue", defaultValue = "Mower"}
07}
08 
09local function playerJoined(player)
10    -- create your leaderstats main
11    local leaderstats = Instance.new("StringValue")
12    leaderstats.Name = "leaderstats"
13    -- for loop through the stats
14    for index, value in pairs(stats) do
15        local stat = Instance.new(value.objectType, leaderstats)
View all 29 lines...
Ad

Answer this question