I have a script and the value of Cash is supposed to change to 999999999
if u have a gamepass, and if u dont then it will just be Cash.Value
, it doesnt work thought and idk why, can somebody please help me, thank you!
Output:
14:45:57.206 - Script 'Players.PurpleProgram.PlayerGui.CashGUI.Cash.Label.LocalScript', Line 7
local player = game.Players.LocalPlayer local cash = player:WaitForChild("leaderstats").Cash local id = 8068400 local service = game:GetService("MarketplaceService") while wait(0.1) do if service:UserOwnsGamePassAsync(player, id) then cash.Value = 9999999999 script.Parent.Text = "Infinite" else script.Parent.Text = cash.Value end end service.PromptGamePassPurchaseFinished:Connect(function(player,ido,purchased) if purchased and ido == id then wait (1) cash.Value = 9999999999 script.Parent.Text = "Infinite" else script.Parent.Text = cash.Value end end)
I believe these scripts will work as you want to. Although I can not promise anything. Please tell me if and what the errors are and I will try to fix it.
Local Script
local player = game.Players.LocalPlayer local cash = player:WaitForChild("leaderstats").Cash local id = 8068400 local remEvent = game.ReplicatedStorage.GamePass -- Change this to the name of your RemoteEvent local secondRemEvent = game.ReplicatedStorage.BuyGamePass -- Change this to the name of your second RemoteEvent local label = script.Parent remEvent:FireServer(id) secondRemEvent.OnClientEvent:Connect(function(succes) -- The "player" argument is only to tell which player who should recieve the signal if succes then cash.Value = "9999999999" label.Text = "Infinite" end end) remEvent.OnClientEvent:Connect(function(ido, purchased) -- The "player" argument is only to tell which player who should recieve the signal if purchased and ido == id then wait(1) cash.Value = "9999999999" label.Text = "Infinite" else label.Text = "cash.Value" end end)
Server Script
local service = game:GetService("MarketplaceService") local remEvent = game.ReplicatedStorage.GamePass -- Change this to the name of your RemoteEvent local secondRemEvent = game.ReplicatedStorage.BuyGamePass -- Change this to the name of your second RemoteEvent local succes = false remEvent.OnServerEvent:Connect(function(player, id) -- The player argument is sent automatically when a Client fires a RemoteEvent if service:UserOwnsGamePassAsync(player, id) then succes = true secondRemEvent:FireClient(player, succes) end end) service.PromptGamePassPurchaseFinished:Connect(function(player, id, purchased) remEvent:FireClient(player, id, purchased) end)
Edit: You should create two RemoteEvents and place them in ReplicatedStorage. Place the Server Script in ServerScriptService. And just change the code in the LocalScript you already had. Please respond with the error if it's not working.
So, the reason it won’t change is because leaderstats cannot be changed on the client due to filtering enabled. Create a remote event in ReplicatedStorage and call it ChangeMoney, then write this code
LocalScript
local player = game.Players.LocalPlayer local gamePassId = 8068400 local MPS = game:GetService("MarketplaceService") local RS = game:GetService("RunService") local Event = game:GetService("ReplicatedStorage"):WaitForChild("ChangeMoney") while RS.Heartbeat:Wait() do if MPS:UserOwnsGamePassAsync(player, id) then Event:FireServer(math.huge) script.Parent.Text = "Infinite" else script.Parent.Text = cash.Value end end MPS.PromptGamePassPurchaseFinished:Connect(function(plr, ido, hasPurchased) if hasPurchased and ido == gamePassId then wait(1) Event:FireServer(math.huge) script.Parent.Text = "Infinite" else script.Parent.Text = cash.Value end end)
ServerScript
local Event = game:GetService("ReplicatedStorage"):WaitForChild("ChangeMoney") Event.OnServerEvent:Connect(function(plr, value) plr:WaitForChild("leaderstats").Cash.Value = value end)