This script incorrectly creates a leaderstat and saves it with the DataStoreService.
Parent of this script is ServerScriptService.
local stat = "Cash"
local startamount = 2500
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = stat
Cash.Value = ds:GetAsync(player.UserId) or startamount
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)
Yes I have access allowed.
It works when I join the game and use console and type
game.Players.voideriaa.leaderstats.Cash.Value = 100
then I leave and rejoin and the Data Save worked but it doesn’t work when you get the output change from the ball function which is the gamble part of my gamble
(you get the money to your leaderstat but it doesn’t save on rejoin)
function SpawnBall()
if bet == 0 then
else
alreadyBet = true
if game.Players.LocalPlayer.leaderstats.Cash.Value >= bet then
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - bet
local RS = game:GetService("ReplicatedStorage")
local BallList = RS:WaitForChild("PlinkoBalls")
local Balls = BallList:GetChildren()
local items = BallList:GetChildren()
local randomBall = items[math.random(1, #items)]
alreadyBet = true
print("Low Risk Ball Purchased")
local ballCopy = randomBall:Clone()
for i = 1, #Balls do
ballCopy.Parent = game.Workspace.Plinko.Balls
ballCopy.Name = "PlinkoBall"
ballCopy.Value.Value = bet
end
if alreadyBet == true then
print(ballCopy)
return
end
end
end
end
local riskType = script.Parent.Parent.risk.Text
if riskType == "LOW RISK" then
for I,Risks in pairs(game.ReplicatedStorage.LowRisk:GetChildren()) do
--will clone all parts inside this folder.... so it will print something in the Output, and points may be allocated ( currently will not work because you must create your own system of points )
local T = Risks:Clone()
T.Parent = game.Workspace.LowRisk
--T.Parent = game.Workspace.LowRisk
T.Touched:Connect(function(Hit)
if T.Name == "0.5x" then
print("0.5x Outcome")
local outcome = bet * 0.5
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + outcome
end
if T.Name == "1.0x" then
print("1.0x Outcome")
local outcome = bet * 1.0
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + outcome
end
if T.Name == "1.3x" then
print("1.3x Outcome")
local outcome = bet * 1.3
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + outcome
end
if T.Name == "1.5x" then
print("1.5x Outcome")
local outcome = bet * 1.5
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + outcome
end
if T.Name == "2.0x" then
print("2.0x Outcome")
local outcome = bet * 2.0
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + outcome
end
if T.Name == "3.5x" then
print("3.5x Outcome")
local outcome = bet * 3.5
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + outcome
end
Hit:Destroy() -- Destroy the cloned ball
if T.Name == "0.8x" then
print("0.8x Outcome")
local outcome = bet * 0.8
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + outcome
end
end)
end
end
script.Parent.MouseButton1Click:Connect(SpawnBall)