Hello, I am trying to make a GUI where you can purchase a tool. I’m trying to just make a button that will take away your Tokens (the in game currency) and give you the tool which is in a folder in Replicated storage called Tools, and the tool is called “Plank”. I have tried myself and tried to watch a tutorial. However the tutorials use a local script which don’t really take away the currency. I need help, please!
1 Like
Add a RemoteEvent called “GiveTool” In ReplicatedStorage, Change the itemname variable to the item you want to give.
Also add an IntValue inside of each tool inside the script called “Cost”, I’m assuming your currency is called Coins.
Add a Local Script inside the button.
local Button = script.Parent
local itemname = "Plank"
Button.MouseButton1Click:Connect(function()
if game.ReplicatedStorage.Tools:FindFirstChild(itemname) then
if game.Players.LocalPlayer.leaderstats.Coins.Value >= game.ReplicatedStorage.Tools[itemname].Cost.Value then
game.ReplicatedStorage.GiveTool:FireServer(itemname)
end
end
end)
Add a Server Script inside ServerScriptService
game.ReplicatedStorage.GiveTool.OnServerEvent:Connect(function(player, tool)
if game.ReplicatedStorage.Tools:FindFindFirstChild(tool) then
if player.leaderstats.Coins.Value >= game.ReplicatedStorage.Tools[tool].Cost.Value then
player.leaderstats.Coins.Value -= game.ReplicatedStorage.Tools[tool].Cost.Value
game.ReplicatedStorage.Tools[tool]:Clone().Parent = player.Backpack
end
end
end)
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.