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

Players cant see other people scores on the leaderboard (+not saving)?

Asked by 2 years ago

I've been making a game where you have to click a button to gain jump power, but later I realized that the stats won't save and people can't see others score on the board, they only see their score. This is my local script for the button and my leaderboard. Tell me if you need to see other scripts or anything.

local script:

local player = game.Players.LocalPlayer
local jumpPower = player:WaitForChild("leaderstats"):WaitForChild("Jump Power")
local RS = game.ReplicatedStorage
local ClickedEvent = RS.Clicked

local debounce = false

function onClicked()
    if debounce == false then
        debounce = true
        jumpPower.Value = jumpPower.Value + 0.1
        if player:WaitForChild("PremiumDouble").Value == true then
            jumpPower.Value = jumpPower.Value + 0.1
        end
        ClickedEvent:FireServer()
        script.Parent.Sound:Play()
        wait(0.2)
        debounce = false
    end
end

script.Parent.MouseButton1Click:Connect(onClicked)

leaderboard:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("SkinStats") -- maybe this needs to be changed lmk

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player

    local JumpPower = Instance.new("NumberValue")
    JumpPower.Name = "Jump Power"
    JumpPower.Value = 0
    JumpPower.Parent = Leaderstats

    local Wins = Instance.new("IntValue")
    Wins.Name = "Wins ????"
    Wins.Value = 0
    Wins.Parent = Leaderstats

    local PremiumDouble = Instance.new("BoolValue")
    PremiumDouble.Name = "PremiumDouble"
    PremiumDouble.Parent = Player

    local Data = DataStore:GetAsync(Player.UserId)
    if Data then
        JumpPower.Value = Data
        Wins.Value = Data
    end
end)

game.Players.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, {
        ["Cash"] = Player.leaderstats["Jump Power"].Value; 
        ["Kills"] = Player.leaderstats["Wins ????"].Value; 
    })
end)
0
"????" is an emoji sixfirez 33 — 2y
0
ur saying u are using an emoji in your script?? If that's the case you going need to remove the emoji. Emojis do not work in code. theking66hayday 841 — 2y
0
but its a "text"so it will work right sixfirez 33 — 2y
0
Not quite sure, but you are using "Data" as a value for both JumpPower and Wins. Perhaps try doing something along the lines of "Data.Cash" and "Data.Kills" or have some way of connecting each value to its place Mafincho 43 — 2y
View all comments (5 more)
0
thank you sixfirez 33 — 2y
0
Did it work? Mafincho 43 — 2y
0
I didn't see yet, but I'm about to. Could you tell me exactly what to do please? sixfirez 33 — 2y
0
Note to my answer I just posted: It's possible the emoji can be another reason as to why it's not saving data. I suggest using letters and/or numbers without any special symbols/characters. Mafincho 43 — 2y
0
I removed every emoji from my scripts and its still not working like before sixfirez 33 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

I see you are using this code to get the player's data.

if Data then
    JumpPower.Value = Data
    Wins.Value = Data
end

I believe your issue can be because of not loading the data correctly. Both values are addressed as "Data", but how would the game know which one is which?

You use the code below to address the saved data.

["Cash"] = Player.leaderstats["Jump Power"].Value;
["Kills"] = Player.leaderstats["Wins ????"].Value;

So, what I suggest trying is:

if Data then
    JumpPower.Value = Data["Cash"] --or Data.Cash
    Wins.Value = Data["Kills"] --or Data.Kills (I don't have Studio opened right now and can't exactly tell)
end

By the way, I highly suggest using a plugin to view the datastore's saved data. The one I'm using is https://www.roblox.com/library/701506235/DataStore-Editor but it's paid.

Ad
Log in to vote
0
Answered by 2 years ago

You can't use emojis in code is most likely the issue in your script

Hope this helps!!

Answer this question