Hi, so I'm struggling on how to give money to players that own the game pass. Recognizing the game pass owners is working fine, it's the intended features that comes with it that not working. The only way to change it's cash, is by going through ServerStorage, PlayerMoney folder, and the number value which is named after the Player, and setting that value. The code inside the ownsGamepass is what I'm stuck on.
local player = game.Players.LocalPlayer local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,9078528) if ownsGamepass then game.ServerStorage.PlayerMoney.LocalPlayer.Value = game.ServerStorage.PlayerMoney.LocalPlayer.Value + 100000 end
Leaderstats script
local cash = false if Settings.LeaderboardSettings.ShowCurrency then cash = Instance.new("StringValue") cash.Name = Settings.CurrencyName cash.Value = 0 end local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(newPlayer.Name) if PlayerStats ~= nil then if cash then local Short = Settings.LeaderboardSettings.ShowShortCurrency PlayerStats.Changed:connect(function() if (Short) then cash.Value = Settings:ConvertShort(PlayerStats.Value) else cash.Value = Settings:ConvertComma(PlayerStats.Value) end end) end end
note that the async functions like userownspass need to be in a protected function (aka. pcall(function()), if its not, it will probably give out errors, so instead of ownsgamepass, try:
local success,errormsg = pcall(function() game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,youridhere) end) if success then -- Your code here else print("There was an error "..errormsg) end)
and your making the leaderstats script too complex, just use the default leaderstats script
-- Inside serverscript game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" local money = Instance.new("IntValue",leaderstats) money.Name = "Money" money.Value = 0 end)
None of your guys answer work, so I solved it myself. The problem is simply put, I can't use a LocalScript change the value, as it can't access the server storage. I just need to put the gamepass script in a regular script and locate it in the ServerScriptService. I cleaned up the script a bit, but it resulted exactly what I wanted.
local mps = game:GetService("MarketplaceService") local gamepass_id = 9078554 -- Game pass ID game.Players.PlayerAdded:Connect(function(player) if mps:UserOwnsGamePassAsync(player.UserId, gamepass_id) then game.ServerStorage.PlayerMoney:FindFirstChild(player.Name).Value = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name).Value + 500000 end end)