#I want to improve my script
1 messages · Page 1 of 1 (latest)
i cant copy text here so here is link https://pastebin.com/nZgEne6W
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
why is that a problem? you only have to write it once 👍
like if i want to add more data so i need to add many lines and repeat same thing over and over again
there is no way i can just collect all data and make it 1 thing
like how to add a table that have all data ? @mint mural
yeah and sometimes certain pieces of data need to be treated differently to others.
numbers are easy. tables like inventory data is more involved. you maybe haven't reached that point yet, but you will 🙂
oh u mean like tools cant be inside table coins or leaderstats ?
yes leaderstats are numbers that are treated like numbers but they get extra-special treatment as leaderstats
oh ok
it's a bit like that
so like is my data store good or need some fixes ?
tbh this looks like your first data store thing, and for a first it looks good enough 👍
ty 🙂
but i want to improve it
all videos i see just do my way i do it so how i make it better ?
you won't be able to properly improve it, or understand how, short of me telling you exactly what code to put, because you don't yet understand how or why this isn't enough. i can tell you it is (mostly) enough and any forseeable problems are very niche.
in short, you don't need to make it better, until you first understand how and/or why it needs to be better in the first place, assuming it needs to be better at all 
ohh okk
the only forseeable problem at this level is if roblox datastore servers crash and tbh you probably don't need to care about that
i know why it need to be better , first i dont use function but idk how i use it , 2nd i just to while plr.parent do and i know its not that efficient
that's a very hard problem. your code is good enough 👍
lol that's small fry
ok ty and sorry for wasting your time
not a waste, i chose to spend this time how i decided 🙂
ok cya
you can learn a lot by studying the docs https://create.roblox.com/docs/cloud-services/data-stores. anyway ok cya 
my nightmare is reading i just cant focus Y_Y
programming is 90% reading docs and code, 10% actually writing code ~_~
watching yt ?
close enough to reading, but with pictures ;p
ok make sense
just dont take the code at its face value, its like copying code out of a 20 year old book, dont expect it to work first try without your input 
from tutorials or ai etc that is
oh why people add also local success , errormassege = pcall ?
yeah
everything is in the docs
i know pcall to protect from any mistake like if there was weak wifi , or game is laging alot but i know i just use success , saved coins not success , error
look up every keyword, you just never know what you might learn 
yeah it will be very helpful
ohh people use success and error bec if there was any error , so can i put it inside while plr.parent do and add it ? @mint mural
local datastoreservice = game:GetService("DataStoreService")
local coinsdata = datastoreservice:GetDataStore("coinsdata")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
local success , savedcoins = pcall(function()
return coinsdata:GetAsync(plr.UserId)
end)
if success and savedcoins then
coins.Value = savedcoins
else
coins.Value = 0
end
while plr.Parent do
task.wait(60)
local success , error_massege = pcall(function()
return coinsdata:SetAsync(plr.UserId , coins.Value)
end)
if not success then
print(error_massege)
end
pcall(function()
coinsdata:SetAsync(plr.UserId , coins.Value)
end)
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local leaderstats = plr_leave:WaitForChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
pcall(function()
coinsdata:SetAsync(plr_leave.UserId , coins.Value)
end)
end)
like this @mint mural i added while plr.parent
that works
ohh yess i just do something with my own !