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

Buying Item Script Doesn't Work? Currencry Error?

Hey There,

Im The_Saver31

So i make this simple LocalScript:

local player = game.Players.LocalPlayer
local currency = player:WaitForChild("leaderstats").Coin -- Currency Name here.
local item = script.Parent.Parent.Parent.Item
local shop = game.Workspace.Shop
local tool = game.ReplicatedStorage:WaitForChild("Tools")

script.Parent.MouseButton1Click:Connect(function()
    if currency.Value >= shop:FindFirstChild("Part"..item.Value).ItemPrice.Value then
        if player.Backpack:FindFirstChild(shop:FindFirstChild("Part"..item.Value).ItemName.Value) == nil then
            if shop:FindFirstChild("Part"..item.Value) then
                currency.Value = currency.Value - shop:FindFirstChild("Part"..item.Value).ItemPrice.Value
                script.Parent.Text = "Bought"
                script.Parent.BackgroundColor3 = Color3.new(0.7,0.7,0.7)
                script.Parent.Shadow.BackgroundColor3 = Color3.new(0.5,0.5,0.5)
                game.ReplicatedStorage.ShopBuy:FireServer(item.Value)
                wait()
                currency.Value = currency.Value
            end
        end
     end
end)

All Fine! Item cloned, my Coin changed, BUTTT

Here What I Mean:

  1. I Buy Item Priced 100 and my Coin is 200

  2. Item Cloned and my Coi changed to 100

  3. I pick a Coin that will give me 10 Coin

  4. My Coin back to Normal, from 100 to 200 again [+10 because i pick a Coin]

Information: -Script was a LocalScript.

Thank's for Reading!

3 comments

0

Always deduct/add money through a 'Script' NOT 'Local Script'. Use Remote Events

0

It's because you're doing this on a local script. The server won't see any changes to currency if you change it locally.

0

Okay! I'll try it :D

1 answer

✓ Accepted answer

So basically, the only thing that's wrong is that you did the whole thing in a local script. Because the local script is only in charge of everything that only the player can see, such as GUIs, a local script will not change things on the server. To do this, add a remote event to replicated storage and fire it. I also suggest checking the currency again on the server just to make sure the person actually has the cash, so that people who try to hack the game using third party programs don't get the item and have negative cash. I hope this has helped :)

2 comments

1

THANKS A LOT MR.EXPERIENCED!!!!

0

np :)

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