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

DataStore On Cloned Leaderstats Intvalue? Is It Possible?

Asked by 5 years ago
Edited 5 years ago

Hello

I have the api enabled and the place is on roblox....just to get this out of the way.

I'm pretty new to roblox lua and been searching online for some help with a data-stores. I watched some youtube videos, but they have scripted differently. They added there leaderstats and Int-value within the data script.

my issues is;

I have my leaderstats and values inside my server script service and cloned it and used a player added function which when a player joins the clone is put under the players name.

Basically, i have to figure out how to data-store a clone leaderstats intvalue.

Is this even possible to datastore a clone? anyways here was me trying to get this to work

Here is what my server script services looks like (links below), and my leader board clone script.

https://i.gyazo.com/7a165e7345dffa90379fe08a77dc5890.png

https://i.gyazo.com/efd37efc47c21e52627d149de445da6b.png

So, i made another non-local script in server script service and named it Datastore and then below is me testing the intvalue cookies to see if it will save when closed. I ran the game again and the value went back to 0 hehe fail...not sure what too do here....

any suggestions would be appreciated

"To simplify what i'm needing to do is save the cloned cookie intvalue" as you can tell im not sure how to XD

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CookiesSaveSystem")
local ds2 = datastore:GetDataStore("RebirthSaveSystem")
local cookies = game.ServerScriptService.leaderboard.leaderstats.Cookies
local rebirths = game.ServerScriptService.leaderboard.leaderstats.Rebirths
local folder = game.ServerScriptService.leaderboard.leaderstats


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

    cookies.Value = ds1:GetAsync(player.UserId) or 0
    ds1:SetAsync(player.UserId, cookies.Value)

    cookies.Changed:Connect(function()
        ds1:SetAsync(player.UserId, cookies.Value)
    end)

end)

1 answer

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

I probably should've led you to the answer not given it but this should help.

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CookiesSaveSystem")

function savetablefunc(player)--a table is much more efficient for saving
    local savetable = {
        cookies = player.leaderstats.Cookies.Value,
        rebirths = player.leaderstats.Rebirths.Value
    }
         return savetable
end


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

    local clone = script.leaderstats:Clone()--here we clone the files over
    clone.Parent = player

    local save = savetablefunc(player)
    local savedstuff = ds1:GetAsync(player.userId)
    function datapull(player,save) -- here we pull the saved data into the ints we cloned
        player.leaderstats.Cookies.Value = savedstuff.cookies
        player.leaderstats.Rebirths.Value = savedstuff.rebirth
    end
        datapull(player,save)
end)

function savedata(player) --this is just the function to call on leaving 
    local save = savetablefunc(player)
    ds1:SetAsync(player.userId,save)
end

game.Players.PlayerRemoving:Connect(savedata)-- here we save the data on player leaving, you dont need on change its wasteful in most cases
0
You went above and beyond appreciate it. however, do i add this code into my leaderboard script or in a new script i add to server script service? ultraplage 11 — 5y
0
Update - So, i added a new script in server script service pasted your code and got some errors in output. The first one was simple to fix just needed to add an end at the table function .however, once i did this a new problem came datapull underline in red and says "Global datapull is only used in the enclosing function consider change it to local". ultraplage 11 — 5y
0
i can't seem to get it to work....will keep trying ultraplage 11 — 5y
0
Oops! I had a couple errors there, sorry I made this up in the SH editor lol. Try what I’ve just put in. You’ll see edits on line 9 and 24. DinozCreates 1070 — 5y
View all comments (28 more)
0
And to your first question you’ll want to merge your leaderstats script into this one. It’s obviously not formatted exactly how you’ll need it so you’ll have to edit what’s here to make it work. But standalone this datastore should work. DinozCreates 1070 — 5y
0
still getting this error datapull underline in red and says "Global datapull is only used in the enclosing function consider change it to local". ultraplage 11 — 5y
0
What line is it on? I dont see where we'd be getting that error DinozCreates 1070 — 5y
0
Although thats a warning not an error, post your script in your question above. I'd like to see what you've got. DinozCreates 1070 — 5y
0
Besides it warning you, does the script work correctly? DinozCreates 1070 — 5y
0
well, it gives me that warning in output and doesn't say anything else, but i have the game running and get some cookies by going into player and cookie intvalue and chage it to 250 i end the game reopen it and my cookies still at 0....Also when using the script you gave me it breaks my clicking function for my cookie decal....idk why been messing with it for 3 hours now..Gunna take a break hehe ultraplage 11 — 5y
0
You cant change a value in the client and expect it to recieve the change on the server. Thats how filtering enabled works. You would need to recieve the cookies via a server side function. DinozCreates 1070 — 5y
0
Make a "part" with a server sided script that gives you cookies, see if it works that way. DinozCreates 1070 — 5y
0
I managed to get my clicking function to work when your script is used, I added a print function in the end function of your script so when i click end it prints to the output data saved. It did, but when i click run again my cookies are at 0 thinking this is because i haven't added code that loads the data when local players join... ultraplage 11 — 5y
0
So, is this server side? https://i.gyazo.com/3d30e34969a30b7895e7ac61d6910ded.png this is my click function so when a local player click my decal they gain a cookie and this should save right? according to the data script you gave me....when you said server side got confused... ultraplage 11 — 5y
0
The issue is its set up as Cookie in one location, and cookie in another. Make sure  theyre referenced correctly or it wont recognize it(ive corrected this issue on the above script) DinozCreates 1070 — 5y
0
okay, copied and pasted the new script...Does the script you provided load the saved cookies/rebirth when they join again after they left. ultraplage 11 — 5y
0
Yes it does, if you check the script you can see where it loads them in. In scripts you'll reference them as player.leaderstats.Cookies.Value DinozCreates 1070 — 5y
0
how do i know if it saved my cookies? if when i run the game click my cookie decal which gives me cookies and then end the game and rejoin my cookies back at 0.. ultraplage 11 — 5y
0
Is your "cookie decal" script a regular script or a local script? DinozCreates 1070 — 5y
0
I did the above, saved published to roblox api enabled the place is private though. I ran the game, click my cookie decal untill my cookies reached 15 ended game and rejoin and my cookies went back to 0 :( -- i'm sorry, i don't know why its not working. ultraplage 11 — 5y
0
answer to my last question, if its a local script it wont work DinozCreates 1070 — 5y
0
Have One local script inside my startgui thats within a screengui named testing and inside that script is all my upgrades, clicking functions ext.... this code here is for my cookie decal https://i.gyazo.com/3d30e34969a30b7895e7ac61d6910ded.png ultraplage 11 — 5y
0
No. If you want a GUI to add value to a server sided int you need to do it with a remote event. Do you know how to use remote events? DinozCreates 1070 — 5y
0
I have watch roblox youtube guides on remote events, but non of the events showed where tutorials for datastoring intvalues. so, wouldn't be able to do this myself with my roblox lua knowledge hehe....im really new ultraplage 11 — 5y
0
If you'll accept my answer, then make a new one i can assist with this. DinozCreates 1070 — 5y
0
make a new what? ultraplage 11 — 5y
0
question DinozCreates 1070 — 5y
0
if i accept your awnser won't we not be able to talk on here? ultraplage 11 — 5y
0
we can. but this is much too long already lol. start a new one for your remote event issue, as of now the datastore should be fine. DinozCreates 1070 — 5y
0
if you really want to understand what im doing i mostly copied this guys video on how to make a cookie clicker, i just changed the names of the variables to suite me and added a rebirth intvalue...https://www.youtube.com/watch?v=eIAWS4BXF9c ultraplage 11 — 5y
Ad

Answer this question