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

How do you convert in-game currency from cash to gold?

Asked by
TechModel 118
3 years ago
Edited 3 years ago

You think I can search this on YouTuber, but you are wrong. I have this game with a bank system I made and it has gold and cash you can take. I use stats in stead of leaderstats becuase I made a gui that can show the cash locally and privately. I want to create a part with a proximity prompt and if the player has gold and interacts the part with the proximity, it then removes all the gold stats and converts into cash stats and stores it over there. But how will I implement and script it? If there is a youtube video that provides someone I've said, then please let me know. Never done something like this before and that's why Im asking the community if they can help. Thanks.

0
just subtract the cash amount and add it to the gold amount kepiblop 124 — 3y
0
a script parented with the proximity part and that's it? TechModel 118 — 3y
0
Has this been solved yet? MarkedTomato 810 — 3y

2 answers

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

So if I understand you correctly, you have a proximity prompt that is parented to a part. So when you trigger the proximity prompt, it'll convert all the gold to cash.

  1. Insert a part to the workspace and parent a proximity prompt to the part.

  2. Insert a script into the ServerScriptService and write the following code.

  3. I'm gonna use leader stats since I'm not sure how your GUI works.

local proximityPrompt = workspace.Part.ProximityPrompt -- defining the proximity prompt

game.Players.PlayerAdded:Connect(function(client) -- when the play joins. the client parameter will always be known as the player object no matter what you call the parameter

    local leaderstats = Instance.new('Folder') -- creates a folder
    leaderstats.Parent = client -- parents it to the player object
    leaderstats.Name = 'leaderstats' -- has to be named 'leaderstats' to work

    local gold = Instance.new('IntValue') -- creates a value which stores a number value
    gold.Parent = leaderstats
    gold.Name = 'Gold' -- naming the instance

    local cash = Instance.new('IntValue') -- does same thing as gold
    cash.Parent = leaderstats
    cash.Name = 'Cash'
end)

proximityPrompt.Triggered:Connect(function(client) -- when prompt gets triggered
    -- redefining them because Players.PlayerAdded function ended
    local leaderstats = client.leaderstats
    local gold = leaderstats.Gold
    local cash = leaderstats.Cash

    if gold.Value > 0 then -- checking whether the player has gold more than 0
        cash.Value = cash.Value + gold.Value
        gold.Value = 0
    else
        print("Player has no gold")
    end
end)
0
Apologies for the late reply but appreciate the help! TechModel 118 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

its kinda easy to do what u said basically take the example of gold = 3 cash now its hard to explain so ill show u the script:

script.Parent.MouseClick:Connect(function(plr) -- im assuming ur proximity is a clickdetector
local Cash = plr.PlayerGui.MainFrame.Cash.Value -- im assuming this is how ur gui looks like
plr.PlayerGui.MainFrame.Gold.Value = plr.PlayerGui.MainFrame.Gold.Value + Cash * 3
plr.PlayerGui.MainFrame.Cash.Value = 0 -- and there u go
end)                                                              
0
If u want to display new text just write local Display = plr.PlayerGui.MainFrame.Gold.Value plr.PlayerGui.MainFrame.Gold.Text = Display TheUltimateTNTFriend 109 — 3y
0
also.. replace gold with cash and cash with gold lol i did a funny TheUltimateTNTFriend 109 — 3y
0
But then line 2 says Cash is not a valid Member of ScreenGui TechModel 118 — 3y
0
and just making sure im doing things right, what line do i replace the cash with gold? TechModel 118 — 3y

Answer this question