Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Leaderboard Saving not saving the money from increase system?

So the system that increases money adds 5 (Currency) every 60 seconds. But after the money has been added from the increase system. It does not work, It just goes back to 0.

Increase system: [LocalScript in the HUD GUI]

local player = game.Players.LocalPlayer
local team = game.Teams
local I_R = script.Parent.Income_Role
local leaderboard = player.Leaderboard
local MoneyFlow = 5


	if player.Team == team.white
then
	while true do
		wait(5)
		I_R.Amount.Text = "£10"
		I_R:TweenPosition(UDim2.new(0.785, 0,0.115, 0),"In", "Back")
		wait(1)
		leaderboard.Bank.Value = leaderboard.Bank.Value + 10
		wait(2.5)
		I_R:TweenPosition(UDim2.new(1, 1,0.115, 0),"Out", "Back")		
	end
end

Saving System: [Script in ServerScriptService]

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

--// Creating Value's System
game.Players.PlayerAdded:Connect(function(Player)
	local leaderboard = Instance.new("Folder", Player)
	leaderboard.Name= "Leaderboard"
	
	local Bank= Instance.new("IntValue", leaderboard)
	Bank.Name = "Bank" 
	Bank.Value = 0
	
	local Wallet= Instance.new("IntValue", leaderboard)
	Wallet.Name = "Wallet"
	Wallet.Value = 0
	
	local Food= Instance.new("IntValue", leaderboard) --// Ignore this
	Food.Name = "Food"
	Food.Value = 100
	
	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		Bank.Value = Data.Bank 
		Wallet.Value = Data.Wallet 
	end
end)

--// Saving Value's System
game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["Bank"] = Player.Leaderboard.Bank.Value; 
		["Wallet"] = Player.Leaderboard.Wallet.Value;
	})
end)

1 answer

✓ Accepted answer

You’re using a LocalScript to increase. If you do this, you need to use RemoteEvents to communicate between the Client and the Server because of FilteringEnabled.

LocalScript:


local player = game.Players.LocalPlayer
local team = game.Teams
local I_R = script.Parent.Income_Role
local leaderboard = player.Leaderboard
local MoneyFlow = 5
local Remote = Game:GetService(“ReplicatedStorage”):WaitForChild(“MoneyReciever”)

    if player.Team == team.white
then
    while true do
        wait(5)
        I_R.Amount.Text = "£10"
        I_R:TweenPosition(UDim2.new(0.785, 0,0.115, 0),"In", "Back")
        wait(1)
        Remote:FireServer(10)
        wait(2.5)
        I_R:TweenPosition(UDim2.new(1, 1,0.115, 0),"Out", "Back")       
    end
end

New script in ServerScriptServce

local Remote = Instance.new(“RemoteEvent”)
Remote.Parent = game:GetService(“ReplicatedStorage”)

function MoneyGiver(plr, amount)
   local stats = plr:WaitForChild(“Leaderboard”)
   local bank = stats:WaitForChild(“Bank”)

   bank.Value = bank.Value + amount
end

Remote.OnServerEvent:Connect(MoneyGiver)

3 comments

0

Also replace all of my quotation marks because my keyboard is weird.

0

Sadly this does not work. I have done what you said and fixed the quotations but it does not work and i do not get a error

0

Nevermind It Does work i just messed it up myself Thank you :)

This discussion is preserved as it was. New answers, comments, and votes are closed.