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

Why is my folder leaderstats is not showing at my player when I run the game?

Asked by 4 years ago
local currencyName = "Credits"

local killName = "Kills"

local DataStore = game:GetService("DataStoreService"):GetDataStore("Datastore")



game.Players.PlayerAdded:Connect(function(player)

    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player



    local currency = Instance.new("IntValue")
    currency.Name = currencyName
    currency.Parent = folder

    local kill = Instance.new("IntValue")
    kill.Name = killName
    kill.Parent = folder

    local ID = currencyName.."-"..player.UserId
    local ID = killName.."-"..player.UserId
    local savedData = nil

    pcall(function()
        savedData = DataStore:GetAsync (ID)
    end)

    if savedData ~= nil then
        currency.Value = savedData
        kill.Value = savedData
        print("Data loaded")
    else 
        currency.Value = 1000
        kill.Value = 0
        print("New player to the game")
    end


end)

this is my whole script but the script I'm having trouble is this one.


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

I'm sure this is correct. But why does it not show? I use a normal script in serverscriptservice. There is no other script that block this.

0
Try printing the name of folder after you make it. It could be you are looking in the wrong place for leaderstats.  SethHeinzman 284 — 4y
0
Also you don’t have to say ~= nil. You can just say the variable. If the variable isn’t nil it will do what’s in the if statement. Just saves time lol SethHeinzman 284 — 4y
0
I tried searching the leaderstats folder in my explorer. But it doesn't exist like my problem script don't work. eromusics 10 — 4y
0
print(folder.Name) and see if it prints leaderstats. SethHeinzman 284 — 4y
View all comments (6 more)
0
Or say if player:FindFirstChild(“leaderstats”) then print(“hi”) end If leaderstats is in player it will print hi.  Are you getting an error in output? SethHeinzman 284 — 4y
0
not working I decided to make another file and try to use the script. It works! So I just need to copy all my files to a new game. eromusics 10 — 4y
0
That’s odd. If it still doesn’t work check the output. It could be a script causing it to crash. SethHeinzman 284 — 4y
0
eromusics it seems to me that you aren't showing the full script. on line 44 I see an extra end. Is there any part of the script that is a yielding function? ex: WaitForChild(). DollorLua 235 — 4y
0
oh didnt click read extra comments xD sorry DollorLua 235 — 4y
0
By the way there is no errors about the script in the output. If there is any errors I should already know what is the problem. I suspect an item or script is making my script not working at somepoint. eromusics 10 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

The answer is that an item or a script is making the script not working. I try to leave the file for a few minutes and it doesn't work again. So I make a conclusion is that I need to find the script and remove it.

0
Nevermind... still not working. I do think the script is at fault here. I leave a new game file with ONLY that script. works for the first time. Leave it a couple of minute. Try open it again and it's not working eromusics 10 — 4y
0
I finally find out that the local datastore is the cause. I don't exactly know why but when I delete that line it works. eromusics 10 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Your script is correct, this also happens to me. Can you change one of your Int-Values and check if shows?

Answer this question