game.Players.PlayerAdded:connect(function(Player) local leaderstats=Instance.new("StringValue") leaderstats.Parent=Player leaderstats.Name="leaderstats" local lvl=Instance.new("IntValue") lvl.Parent=leaderstats lvl.Parent=leaderstats lvl.Name="Level" repeat wait() until leaderstats end) ---- game.Players.PlayerAdded:connect(function(Player) Player.leaderstats.Level.Changed:connect(function()--line 14 local Debris=game:GetService("Debris") local Light=Instance.new("PointLight") Light.Parent=Player.Character.Torso Light.Brightness=math.huge Light.Color=Color3.new(255,225,0) Debris:AddItem(Light,5) end) end)
the error is leaderstats is not a valid member of Player on line 14. On ROBLOX studio, you can see the value, but I get this error in both studio and in a server.
First: why are you connecting two things to the same event?
That's bound to be confusing. In this case, it's likely the cause of an error, since if the second one acts first, there won't be a leaderstats
objects (when it acts -- though there will be immediately after, as you are observing).
To fix that, we can write the second one using Player:WaitForChild("leaderstats"):WaitForChild("Level").Changed
.
Or we can just use one event.
Here are other issues you should address:
Instance.new
to shorten things upleaderstats
twicerepeat until
loop since the condition will always pass since you just made the leaderstats
object (and nothing can change that in the middle since it's local
)player
if you're going to use other lowercase variable names.math.huge
ever. game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("StringValue", player) leaderstats.Name = "leaderstats" local lvl = Instance.new("IntValue", leaderstats) lvl.Name = "Level" lvl.Changed:connect(function() local light = Instance.new("PointLight", player.Character.Torso) light.Brightness = 60 light.Color = Color3.new(255,225,0) local Debris = game:GetService("Debris") Debris:AddItem(light, 5) end) end)
You should be careful of lvl
changing while the Character doesn't have a torso though.
The following would be safer:
if player.Character and player.Character:FindFirstChild("Torso") then local light = Instance.new ......