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

My buy script isn't working. It only gives u the tool and doesn't take money from u. Please Help!?

Asked by 6 years ago
Edited 6 years ago

Scripts:

local data = game:GetService("DataStoreService"):GetDataStore("Hack3214234hg")
game.Players.PlayerAdded:connect(function(plr)
    local stats = Instance.new("Folder",plr)
    stats.Name = "leaderstats"

    local Money = Instance.new("NumberValue",stats)
    Money.Name = "Money"

    local SavedItems = data:GetAsync(plr.UserId)
    if SavedItems then
        Money.Value = SavedItems.Money or 20
    else
        Money.Value = 20
    end
end)

script.Parent.MouseButton1Click:connect(function()
    local price = script.Parent.Parent.Price
    local player = game.Players.LocalPlayer
    if game.Players.LocalPlayer.leaderstats.Money.Value >= price.Value then
        local item = script.Parent.Parent.Item
        local backpack = player.Backpack
        local starter = player.StarterGear
        local clone = game.ReplicatedStorage.Tools:FindFirstChild(item.Value):Clone()
        local clone2 = game.ReplicatedStorage.Tools:FindFirstChild(item.Value):Clone()
        clone.Parent = backpack
        clone2.Parent = starter
        game.ReplicatedStorage.Buy:FireServer()
    end
end)

game.Players.PlayerRemoving:connect(function(plr)
    local Saving = {["Money"] = plr.leaderstats.Money.Value;
    }
    data:SetAsync(plr.UserId,Saving)
end)

game.ReplicatedStorage.Buy.OnServerEvent:Connect(function(player)
    player.leaderstats.Money.Value = player.leaderstats.Money.Value - player.Price.Value
end)

It doesnt save the leaderstats if i have it in a local script...

0
Hello! can you put your scripts inside Code block? Voxozor 162 — 6y
0
uh ok roo12341234 -8 — 6y

1 answer

Log in to vote
2
Answered by
Voxozor 162
6 years ago

You need to add one more thing [Look at line 5]

script.Parent.MouseButton1Click:connect(function()
    local price = script.Parent.Parent.Price
    local player = game.Players.LocalPlayer
    if game.Players.LocalPlayer.leaderstats.Money.Value >= price.Value then
       game.Players.LocalPlayer.leaderstats.Money.Value - price.Value -- This is what you need to add
        local item = script.Parent.Parent.Item
        local backpack = player.Backpack
        local starter = player.StarterGear
        local clone = game.ReplicatedStorage.Tools:FindFirstChild(item.Value):Clone()
        local clone2 = game.ReplicatedStorage.Tools:FindFirstChild(item.Value):Clone()
        clone.Parent = backpack
        clone2.Parent = starter
        game.ReplicatedStorage.Buy:FireServer()
    end
end)

I hope that helps you. Good luck.

1
Uh the problem is that it isnt saving when im doing that roo12341234 -8 — 6y
1
Do you mean when you rejoin the game doesn't save leaderstats value? Voxozor 162 — 6y
1
Or the tool? Voxozor 162 — 6y
1
dude you need to explain your answers. If you didnt he will never learn lua HaveASip 494 — 6y
View all comments (2 more)
1
The leaderstats roo12341234 -8 — 6y
1
Please make another question. I can't reply again here. Voxozor 162 — 6y
Ad

Answer this question