d

I am trying to make a sword fight game I want a little tool gui to buy different swords. How would i make the button to buy it? (I already have leaderstats)

1 Like

You mean how to script the button or how to make a button?

1 Like

I suggest looking at this :

2 Likes

TY Guys for the help. :smiley:

Like mention above you need to use remoteEvent
Here is an example:
Local Script inside of button:

local Event = game.ReplicatedStorage.RemoteEvent
local toolName = "ToolNameHere"

script.Parent.MouseButton1Click:Connect(function() -- when player clicks the button
   Event:FireServer(toolName)
end)

then script in ServerScriptServices should look something like this:

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player, toolName)
     local clonedTool = game.ReplicatedStorage:FindFirstChild(toolName):Clone()
    clonedTool.Parent = player.Backpack
end)

if you have currency then you should check if player have enough money etc:

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player, toolName)
    if player.leaderstats.Cash.Value => 100 then -- your price here
       
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100 -- again price here
        local clonedTool = game.ReplicatedStorage:FindFirstChild(toolName):Clone()
        clonedTool.Parent = player.Backpack
        
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100 -- your price here
    end
end)

Make sure you have tool in ReplicatedStorage which has same name as your variable etc in Local Script
Hope this helps :slight_smile:

5 Likes