Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

currency not turning into other currency?

i am making a cash to gold system where if the player get 10,000 cash it would turn into gold. there are no errors but its not turning into gold here is me script:

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder",player)
	stats.Name = "leaderstats"
	
	local cash = Instance.new("IntValue",stats)
	cash.Name = "Cash"
	cash.Value = 10
	
	local gold = Instance.new("IntValue",stats)
	gold.Name = "Gold"
	gold.Value = 0


    cash.Changed:Connect(function()
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 0 -- this takes away the cash
		player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1

    end)
end)

1 comment

0

when a reputation 100+ says a question is a "request" but it doesn't ask for anything but help on scripting

1 answer

✓ Accepted answer

Hi, i'm BashGuy10. I can hopefully help you!

Problem?

You're currency is not changing correctly.

Fixes

Use while wait() do or Cash.Changed:Connect(function()

Fix

game.Players.PlayerAdded:Connect(function()
	-- Leader stat creation here
	

	cash.Changed:Connect(function()
		if player.leaderstats.Cash.Value >= 10000 then
			player.leaderstats.Cash.Value = 0 -- Set the value = 0

			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1
		end
	end)
end)

FYI, paste you leaderstat code in to Line 2, and paste gold changing code into Line 6

Roblox wiki link

11 comments

0

Btw i recommend "Cash.Changed"

0

i now got an error: ServerScriptService.Script:22: unexpected symbol near ')'

0

i tried cash.Changed and it says: ServerScriptService.Script:22: 'end' expected (to close 'function' at line 1) near ''

0

Changed it

0

If it still doesn't work, tell me.

0

it worked but it didnt take away the cash

0

Please update your answer with your code

0

I found your problem, im about to edit my answer

0

Please mark this as the solution if i fixed your problem

0

thank you

0

No problem bro

This discussion is preserved as it was. New answers, comments, and votes are closed.