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

Buying Item Script Doesn't Work? Currencry Error?

Asked by 3 years ago

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!

0
Always deduct/add money through a 'Script' NOT 'Local Script'. Use Remote Events Soban06 410 — 3y
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. radiant_Light203 1166 — 3y
0
Okay! I'll try it :D The_Saver31 260 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

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 :)

1
THANKS A LOT MR.EXPERIENCED!!!! The_Saver31 260 — 3y
0
np :) Superexperiencedguy 199 — 3y
Ad

Answer this question