I’m just trying to make a purchase system where when you purchase the in-game product it increases one of the leaderstats by 1 and decreases the other by 5 (separate leaderstats)
I don’t know how I am able to fetch the leaderstats from the player, I have tried doing
local Part = script.Parent.Parent
local ProximityPrompt = script.Parent
local ls = game.Players.LocalPlayer.leaderstats.Pounds
ProximityPrompt.Triggered:connect(function(Player)
-- Add value to one of the players leaderstats
-- Remove value from a different leaderstat
end)
If something doesn’t make sense, please let me know.
Thank you!
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("POUNDID:36729346DDX")
local ds2 = dsService:GetDataStore("MacopolyID:36729346DDX")
local ran = math.random(1,5)
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local currency = Instance.new("IntValue", folder)
currency.Name = "Pounds"
currency.Value = ds:GetAsync(plr.UserId) or 0
currency.Changed:Connect(function()
ds:SetAsync(plr.UserId, currency.Value)
end)
local Mac = Instance.new("IntValue", folder)
Mac.Name = "Macopoly Tickets"
Mac.Value = ds2:GetAsync(plr.UserId) or 0
Mac.Changed:Connect(function()
ds2:SetAsync(plr.UserId, Mac.Value)
end)
while true do
currency.Value = currency.Value + ran
wait(60)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, plr.leaderstats.Money.Value)
end)
ok I made some edits so its not a forever loop, it should exit when the player leaves the game,
also your random was not in the loop meaning it would have the same value for the added money every minute
It works great thank you, but it doesn’t really answer my initial question.
In a separate script I am wanting to be able to change the leaderstat values
But my issue is I don’t know how I can actually find the players leaderstat to alter them.
You’re editing the values on “localplayer” they will not replicate.
Use this instead.
local Part = script.Parent.Parent
local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:connect(function(Player)
currency = Player:WaitForChild("leaderstats"):WaitForChild("Pounds")
currency2 = Player:WaitForChild("leaderstats"):WaitForChild("Macopoly Tickets")
currency.Value = currency.Value -= 5 -- this will change pounds value
currency2.Value = currency2.Value += 1 -- this will change tickets value
end)
I get no errors, just warnings telling me to change the “currency” variable to local (which I have tried)
And “-=” just gave me an error so I changed it to “-”
local Part = script.Parent.Parent
local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:connect(function(Player)
currency = Player:WaitForChild("leaderstats"):WaitForChild("Pounds")
currency2 = Player:WaitForChild("leaderstats"):WaitForChild("Macopoly Tickets")
currency.Value = currency.Value - 5 -- this will change pounds value
currency2.Value = currency2.Value + 1 -- this will change tickets value
end)
local Part = script.Parent.Parent
local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:connect(function(Player)
local currency = Player:WaitForChild("leaderstats"):WaitForChild("Pounds")
local currency2 = Player:WaitForChild("leaderstats"):WaitForChild("Macopoly Tickets")
currency.Value -= 5 -- this will change pounds value
currency2.Value += 1 -- this will change tickets value
end)