What's wrong with my cash script?

local mps = plr.leaderstats.MPC.Value
plr.leaderstats.Cash.Value += mps
   if plr.leaderstats.amethystupgrade == Color3.new(“1,1,2”) then
   local x = math.random(0,plr.leaderstats.AMPC)
   plr.leaderstats.Amethyst.Value += x
    end
end)```
1 Like

What doesn’t work in your script?

1 Like

The part where it gives cash. I can give the leaderstat script if you want

1 Like

amethystupgrade is a value? if so, you should place

if plr.leaderstats.amethystupgrade.Value == Color3.new(“1,1,2”) then

Same below

 local x = math.random(0,plr.leaderstats.AMPC.Value)

Especially in the second, that is wrong yes or yes, if its a value you must put “.Value” and if it isnt, then it has to be a numerical value not an object …
Is that what is wrong?

2 Likes

Thank you, but I am still not getting cash. I am getting the other currency, amethyst, however.

1 Like

Add WaitForChild method. Sometimes leaderstats can’t load on time and script doesn’t detect folder.

local leaderstats = plr:WaitForChild("leaderstats")

local cash = leaderstats:WaitForChild("Cash")

local mps = leaderstats:WaitForChild("MPC")

cash.Value += mps.Value

if leaderstats:WaitForChild("amethystupgrade") == Color3.new(1,1,2) then

local ampc = leaderstats:WaitForChild("AMPC") -- Be sure it is an intValue

local x = math.random(0,ampc.Value)

local amethyst = leaderstats:WaitForChild("Amethyst")

amethyst.Value += x

end

end)
1 Like

Not working, thanks for your help, though

1 Like

If there are no errors in the output, it is likely that the if statement did not execute. If the condition is false (example: 4 + 4 = 10), the code in the condition will not execute.

Are you sure there is amethystupgrade?
Are you sure it is Color3Value?

It cannot be anything other than Color3Value.

Code
local leaderstats = plr:WaitForChild("leaderstats")

local cash = leaderstats:WaitForChild("Cash")

local mps = leaderstats:WaitForChild("MPC")

local amethystupgrade = leaderstats:WaitForChild("amethystupgrade") -- This must be a Color3Value

cash.Value += mps.Value

if amethystupgrade.Value == Color3.new(1,1,2) then

local ampc = leaderstats:WaitForChild("AMPC") -- Be sure it is an intValue

local x = math.random(0,ampc.Value)

local amethyst = leaderstats:WaitForChild("Amethyst")

amethyst.Value += x

else

print("W") -- will print 'w' if the If statement is not met

end

end)

How is player defined in this script?

1 Like