Script in ServerScriptService
local event1 = game.ReplicatedStorage:WaitForChild("Events").PurchaseStorage local Money= game.Players.LocalPlayer.Money game.ReplicatedStorage.Events.PurchaseStorage.OnServerEvent:Connect(function(plr, event1) if Money.Value >= 10000 then Money.Value = Money.Value - 10000 else if Money.Value <= 9999 then end end end)
Localscript
local evnt = game.ReplicatedStorage:WaitForChild("Events").PurchaseStorage local plr = game.Players.LocalPlayer script.Parent.MouseButton1Down:Connect(function() if plr.Money.Value >= 10000 then script.Parent.Parent.Parent.Parent.Parent.Parent.Success.Visible = true wait(3) script.Parent.Parent.Parent.Parent.Parent.Parent.Success.Visible = false evnt:FireServer("03X") elseif plr.Money.Value <= 9999 then script.Parent.Parent.Parent.Parent.Parent.Parent.Error.Visible = true wait(3) script.Parent.Parent.Parent.Parent.Parent.Parent.Error.Visible = false end end)
Any idea why this does nothing to the Money value?
game.Players.PlayerAdded:connect(function(plr) local Money = Instance.new("IntValue", plr) Money.Name = "Money" Money.Value = 1000 local rubys = Instance.new("IntValue", plr) rubys.Name = "Rubys" rubys.Value = 10 end)
Hopefully this can help you with your scripts also make sure to read little notes i have left on the script :)
first the leaderboard script
--this is the leaderboard its auto save so dont worry local datastore = game:GetService("DataStoreService")--/ \ local MyMoney = datastore:GetDataStore("MoneyData")--getting DataStoreService to store Data | local MyRuby = datastore:GetDataStore("RubyData")--------\ / game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats"-- making a folder and naming it leaderstats to store money and Ruby in. local Money = Instance.new("IntValue", leaderstats) Money.Name = "Money" -- Money local Ruby = Instance.new("IntValue", leaderstats) Ruby.Name = "Ruby's" -- Ruby Money.Value = MyMoney:GetAsync(player.UserId) or 0 -- player joins give his amount of saved Money or set to 0 if its tha players first time MyMoney:SetAsync(player.UserId, Money.Value) -- setting the players data as he joins Ruby.Value = MyRuby:GetAsync(player.UserId) or 0 MyRuby:SetAsync(player.UserId, Ruby.Value) game.Players.PlayerRemoving:connect(function() -- playing functon when the player leaves MyMoney:SetAsync(player.UserId, Money.Value) -- setting the players money for when he joins this is the amount he will be given MyRuby:SetAsync(player.UserId, Ruby.Value) end) end)
this leaderboard has 2 values Money and Ruby they both auto save when the player leaves the game
next will be the script in ServerScriptService
which is used on a function to take away the players money and give him his item or what ever you desire
game.ReplicatedStorage.Events.PurchaseStorage.OnServerEvent:Connect(function(player)-- function playing on PurchaseStorage print("Working!") -- print working to know if the function has been played if player.leaderstats.Money.Value >= 10000 then -- checks if the player has enough money player.leaderstats.Money.Value = player.leaderstats.Money.Value - 10000 -- if he does subtract money print("Enough Money!") -- if has enough money print Enough Money to check if teh script is working else if player.leaderstats.Money.Value < 9999 then print("Not Enough Money") -- if player doesnt have enough, it does nothing and prints "Not Enough Money" end end end)
if youve noticed in the Buying script i removed the local variables such as local money = game.players.localplayers -- etc...
and that because these can only work in a local script and you can get the Game.Players.Localplayers
part from the player
at the end of the fire server line after function
after that you can simply put leaderstats.Money.Value
hopefully this helped you accomplish what ever you were trying to seek if you have any problems or question about the scripts or any other script just ask :)