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

How do i make an script that on an event adds a value to a leaderstat?

I am working on a Minigame like system and i seem to be having a brain fart, im not quite sure how to add a value onto the leader stats when there is an event. Here is my leaderstat script :

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("WinsSaveSystem")
local ds2 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "leaderstats"
 local wins = Instance.new("IntValue", folder)
 wins.Name = "Wins"
 local cash = Instance.new("IntValue", folder)
 cash.Name = "Cash"
 
 wins.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, wins.Value)
 
 cash.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, cash.Value)
 
 wins.Changed:connect(function()
  ds1:SetAsync(plr.UserId, wins.Value)
 end)
 
 cash.Changed:connect(function()
  ds2:SetAsync(plr.UserId, cash.Value)
 end)
end) 

I just want to add a script that makes a value of "Wins" and "Cash" Go up

I already tried

player.leaderstats.wins.Value = Player.leaderstats.wins.Value +1

Thank you

2 comments

0

It’s proffered to use :GetPropertyChangedSignal(property):Connect() for property changes events.

0

its the same, because on value objects, .Changed only fires on the Value property

1 answer

How the script works is that once the mini-game ends it returns the winner and runs a function event

local settingsModule = require(waitForChild(script, "Settings")) local onWin = (function() local onWinModule = findFirstChild(script, "OnWin")

if onWinModule then
	local onWinFunction = require(onWinModule)
	
	if type(onWinFunction) == "function" then
		return onWinFunction
	end
end

end)()

In the script titled OnWin it has this script

return function(winner) player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1 end end ---------- This is giving the error :

Workspace.Minigames.Main.OnWin:4: '' expected near 'end'

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