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

why isn't it showing up on the leader stats?

Asked by 1 year ago
Edited 1 year ago

im new to scripting and ive tried to fix the script and watch youtube videos to learn what i did wrong but i cant figure it out.

local datastoreservice = game:GetService("DataStoreService")
local clicksDataStore = datastoreservice:GetDataService("clicks")

game.players.playerAdded:connect(function(player)
    local leaderstats = Instance.new("folder",player)
    leaderstats.name = "leaderstats"

    local clicks = Instance.new("IntValue",leaderstats)
    clicks.name = "clicks"
    clicks.value = 0

    local playeruserId = "player_"..player.UserId

    -- Loading Data
    local clicksData
    local success, errormessage = pcall(function()
        clicksData = clicksDataStore:GetAsync(playeruserId)

    end)
    if success then
        clicks.value = clicksData
    end
end)

this is the part that isn't working and I dont know why.

0
Your main problem is use of capitals in game.Players.PlayerAdded. It should be as i just wrote it Protogen_Dev 268 — 1y
0
Whats says the output? horvathmf 10 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

--Created by : MarkHunHMD --Put in your ServerScriptService and make a SIMPLE leaderstats script

local dataStoreService = game:GetService("DataStoreService") local leaderstatsDataStore = dataStoreService:GetGlobalDataStore("leaderstats")

local loaded = {}

game.Players.PlayerAdded:connect(function(player) local leaderstats = player:WaitForChild("leaderstats")--Your leaderstats name if player.UserId > 0 and player.Parent then local leaderstatsData = leaderstatsDataStore:GetAsync(player.UserId) if leaderstatsData ~= "Request rejected" then if leaderstatsData then for i, stat in ipairs(leaderstats:GetChildren()) do local value = leaderstatsData[stat.Name] if value then stat.Value = value end end end loaded[player] = true end end end)

game.Players.PlayerRemoving:connect(function(player) local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then if loaded[player] then local leaderstatsData = {} for i, stat in ipairs(leaderstats:GetChildren()) do leaderstatsData[stat.Name] = stat.Value end leaderstatsDataStore:SetAsync(player.UserId, leaderstatsData) end else Instance.new("Folder", player).Name = "leaderstats" end loaded[player] = nil end)

Ad

Answer this question