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

Making a LvL only door, output shows "LocalPlayers is not a valid member of Players". How do i fix? [closed]

Asked by 5 years ago

****full script in the door part:

script.Parent.Touched:Connect(function()
    if game.Players.LocalPlayers.leaderstats.Level >= 2 then
        script.Parent.CanCollide = false
    end
end)

line 2 is the problem

Don't know if this is important, but this is the leaderstats script in serverscriptservice

local level = 1
local exp = 0
local axp = 20

local InStudio = game:GetService("RunService"):IsStudio()

if not InStudio then
    level = game:GetService("DataStoreService"):GetDataStore("Levels")
    exp = game:GetService("DataStoreService"):GetDataStore("EXP")
    axp = game:GetService("DataStoreService"):GetDataStore("AXP") 
end

function savedata(dataname, playerid, value)
    if InStudio then return end
    dataname:SetAsync(playerid, value)
end

game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder")
    leader.Name = "leaderstats"
    leader.Parent = player
    local levelz = Instance.new("IntValue")
    levelz.Name = "Level"
    local xpz = Instance.new("NumberValue")
    xpz.Name = "Exp"
    local xpn = Instance.new("IntValue")
    xpn.Name = "ExpNeeded"

    if not InStudio then
        xpn.Value = axp:GetAsync(tostring(player.userId)) or 20
        xpz.Value = exp:GetAsync(tostring(player.userId)) or 0
        levelz.Value = level:GetAsync(tostring(player.userId)) or 1
    else
        xpn.Value = axp
        xpz.Value = exp
        levelz.Value = level
    end

    levelz.Parent = leader
    xpz.Parent = leader
    xpn.Parent = leader

    xpz.Changed:connect(function()
        if player.leaderstats:WaitForChild("Exp").Value >= player.leaderstats:WaitForChild("ExpNeeded").Value then
            levelz.Value = levelz.Value + 1


            xpn.Value = math.floor(xpn.Value * 2) 

            savedata(level, player.userId, levelz.Value)
            savedata(exp, player.userId, xpz.Value)
            savedata(axp, player.userId, xpn.Value)
        else
            savedata(level, player.userId, levelz.Value)
            savedata(exp, player.userId, xpz.Value)
            savedata(axp, player.userId, xpn.Value)
        end
        savedata(level, player.userId, levelz.Value)
        savedata(exp, player.userId, xpz.Value)
        savedata(axp, player.userId, xpn.Value)
    end)
end)

game.Players.PlayerRemoving:connect(function(player)
    savedata(level, player.userId, player.leaderstats.Level.Value)
    savedata(exp, player.userId, player.leaderstats.Exp.Value)
    savedata(axp, player.userId, player.leaderstats.ExpNeeded.Value)
end)
0
Locking question as error was caused due to a simple typographical error. LocalPlayer... User#24403 69 — 5y

Locked by User#24403

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?