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

leaderstats is not a valid member of Player?

Asked by 5 years ago

Yesterday i was working on a new game (my first one as you could probably tell) but the code and everything worked fine yesterday and didnt change anything after that anymore, now that i want to continue working today i try running the game to make sure everything is still fine and i get met with the message: leaderstats is not a valid member of Player and i dont know whats wrong, could someone help? heh. again. Thanks!

01local DataStore = game:GetService("DataStoreService")
02local PointsData = DataStore:GetOrderedDataStore("Points")
03 
04game.Players.PlayerAdded:Connect(function(player)
05    local points = PointsData:GetAsync(player.UserId)
06    local leaderstats = Instance.new("Folder")
07    leaderstats.Name = "leaderstats"
08    local pointsValue = Instance.new("IntValue",leaderstats)
09    pointsValue.Value = points
10    leaderstats.Parent = player
11    pointsValue.Name = "Strength"
12end)
13 
14game.Players.PlayerRemoving:Connect(function(player)
15    local strength = player.leaderstats.Strength.Value
View all 28 lines...

1 answer

Log in to vote
0
Answered by 5 years ago

When you do:

1local leaderstats = Instance.new("Folder")

Replace that line of code with

1local leaderstats = Instance.new("Folder",player)
0
It is highly recommended that you do not use the second parameter of Instance.new(). You should set the Parent after you have set anything else you want to set, such as the Name of the Instance. DeceptiveCaster 3761 — 5y
Ad

Answer this question