Hey guys,
today i was messing around in studio for fun, and i tried to change my leaderstats with a script, but it didnt change. the script is inside the textlabel:
--scripted by anirudh851
--this script saves and loads player's money
local DataStoreService = game:GetService("DataStoreService")
local PlayerCashDatastore = DataStoreService:GetDataStore("PlayerCashDatastore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Cash"
local data
local success, errormessage = pcall(function()
data = PlayerCashDatastore:GetAsync(player.UserId.."-cash")
end)
if success then
cash.Value = data
else
print("There was an error getting your data:")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
PlayerCashDatastore:SetAsync(player.UserId.."-cash", player.leaderstats.Cash.Value)
end)
if success then
print("Data succesfully saved")
else
print("There was an error saving your data:")
warn(errormessage)
end
end)
its pretty long as it saves and loads the data from data stores too
That is not possible, since the server does not have a player that is local to the server. I think that this used to work in Roblox Studio back in the day, but it will not work in a server.