Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Not Changing Value of Cash if Gamepass?

Asked by
Rynappel 212 Moderation Voter
4 years ago

I have a script and the value of Cash is supposed to change to 999999999if 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)
0
Is this a local script or server script? MegaManSam1 207 — 4y
0
Local Rynappel 212 — 4y
0
Leaderstats can only be accessed by the server, so you need to use a RemoteEvent to send a message to the server to update the player's currency. MegaManSam1 207 — 4y
0
example? Rynappel 212 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

0
Not working Rynappel 212 — 4y
0
Why did you accept if it's not working? Spjureeedd 385 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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)
0
lmao thats correct! ImAnonymousBan 24 — 4y
0
ALOT of errors in the code, i fixed them but it still doesnt work, ;-; Rynappel 212 — 4y
0
ALOT of errors in the code, i fixed them but it still doesnt work, ;-; Rynappel 212 — 4y

Answer this question