So i using free models and they are not working as i want to, I need that you need money to buy guns not just take them.
COMMUNITY QUESTION
How should i make item shop that you need money to buy things?
1 answer
Alrighty, we have a ton of work to do! Let's get started.
First off you're going to need a DataStore! This is in a script I created called leaderstats.
local DataStoreKey = 'EnterHere' -- Make this absolutely random!
local currencything = 'EnterCurrencyHere' -- What's the name of the currency?
local DSService = game:GetService('DataStoreService'):GetDataStore(DataStoreKey)
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = "id-"..plr.userId
local leaderstats = Instance.new('IntValue',plr)
local savevalue = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = currencything
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey,NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = "id-"..plr.userId
local Savetable = plr.leaderstats[currencything].Value
DSService:SetAsync(uniquekey,Savetable)
end)
Once this script is created, I recommend you place it in ServerScriptService just like I had.
Now, let's assume that we're putting a buy script inside a GUI button that gives you a tool after buying.. Here's what you'd type out:
local Button = script.Parent
local Player = game.Players[Button.Parent.Parent.Parent]
local ToolRecievedAfterPurchase = script:FindFirstChildOfClass("Tool")
Button.MouseButton1Click:Connect(function()
if Player.leaderstats["EnterCurrencyHere"].Value > 5 then
ToolRecievedAfterPurchase:Clone().Parent = Player:FindFirstChild("Backpack")
Player.leaderstats["EnterCurrencyHere"].Value = Player.leaderstats["EnterCurrencyHere"].Value - 5
elseif Player.leaderstats["EnterCurrencyHere"].Value < 5 then
print(Player.Name..' cannot afford a(n) '..ToolRecievedAfterPurchase.Name)
end
end)
If this doesn't work, consider friending me on roblox at TheFunnyKind or at pingsock, and I can help you out a bit more.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I dont understand where does it say how much does it cost.