Making a LvL only door, output shows "LocalPlayers is not a valid member of Players". How do i fix? [closed]
****full script in the door part:
1 | script.Parent.Touched:Connect( function () |
2 | if game.Players.LocalPlayers.leaderstats.Level > = 2 then |
3 | script.Parent.CanCollide = false |
line 2 is the problem
Don't know if this is important, but this is the leaderstats script in serverscriptservice
05 | local InStudio = game:GetService( "RunService" ):IsStudio() |
08 | level = game:GetService( "DataStoreService" ):GetDataStore( "Levels" ) |
09 | exp = game:GetService( "DataStoreService" ):GetDataStore( "EXP" ) |
10 | axp = game:GetService( "DataStoreService" ):GetDataStore( "AXP" ) |
13 | function savedata(dataname, playerid, value) |
14 | if InStudio then return end |
15 | dataname:SetAsync(playerid, value) |
18 | game.Players.PlayerAdded:connect( function (player) |
19 | local leader = Instance.new( "Folder" ) |
20 | leader.Name = "leaderstats" |
21 | leader.Parent = player |
22 | local levelz = Instance.new( "IntValue" ) |
24 | local xpz = Instance.new( "NumberValue" ) |
26 | local xpn = Instance.new( "IntValue" ) |
27 | xpn.Name = "ExpNeeded" |
30 | xpn.Value = axp:GetAsync( tostring (player.userId)) or 20 |
31 | xpz.Value = exp:GetAsync( tostring (player.userId)) or 0 |
32 | levelz.Value = level:GetAsync( tostring (player.userId)) or 1 |
39 | levelz.Parent = leader |
43 | xpz.Changed:connect( function () |
44 | if player.leaderstats:WaitForChild( "Exp" ).Value > = player.leaderstats:WaitForChild( "ExpNeeded" ).Value then |
45 | levelz.Value = levelz.Value + 1 |
48 | xpn.Value = math.floor(xpn.Value * 2 ) |
50 | savedata(level, player.userId, levelz.Value) |
51 | savedata(exp, player.userId, xpz.Value) |
52 | savedata(axp, player.userId, xpn.Value) |
54 | savedata(level, player.userId, levelz.Value) |
55 | savedata(exp, player.userId, xpz.Value) |
56 | savedata(axp, player.userId, xpn.Value) |
58 | savedata(level, player.userId, levelz.Value) |
59 | savedata(exp, player.userId, xpz.Value) |
60 | savedata(axp, player.userId, xpn.Value) |
64 | game.Players.PlayerRemoving:connect( function (player) |
65 | savedata(level, player.userId, player.leaderstats.Level.Value) |
66 | savedata(exp, player.userId, player.leaderstats.Exp.Value) |
67 | savedata(axp, player.userId, player.leaderstats.ExpNeeded.Value) |