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

How would i add a equip and unequp function to this store gui?

Asked by 6 years ago
Edited 6 years ago

I made this store gui were you have a certain number of coins, then you are able to buy a gun. But the problem is, you buy the gun and it stays in your inventory forever. So my players, will be buying a lot of items, but with it doing this the items will pile in the inventory. However, if i can script this "on mouseclick1 remove item" without charging player again. Then "on mouseclick1 add item" something like that. so the first time it charges you once it know the item has been bought it will activate the equip and unequip. Has anyone worked with this? if so could you share some facts so i can get this complete?

local player = game.Players.LocalPlayer
local leaderboard = player:WaitForChild("leaderstats")
local button = script.Parent
local price = button:WaitForChild("Price")
local item = button:WaitForChild("ItemName")
local rs = game:GetService("ReplicatedStorage")

button.MouseButton1Click:connect(function()
    if leaderboard.Coins.Value >= price.Value then -- Change "Coins" to your currency name...
        leaderboard.Coins.Value = leaderboard.Coins.Value - price.Value
        local item = rs:WaitForChild(item.Value)
        item:Clone().Parent = player.StarterGear
        item:Clone().Parent = player.Backpack
    end
end)

while wait() do
    button.Text = item.Value.." - "..price.Value
end

1 answer

Log in to vote
1
Answered by 6 years ago

Well, I'm rather new to scripting myself, so I might not be a help. Anyways, You might be able to achieve what you want to do with a few variables that can determine whether the item has been bought or not. For example, You could try to make a variable that is false by default, but is set to true once the item is bought. Then, you can create a separate set of actions for when the item has already been bought.

Although unrelated, there is an article that might be of use on the wiki here. It's about something called debouncing, where you use variables in this way to cap the amount of times something can happen within a certain amount of time, but you can use some of the methods there to help you out.

Again, sorry if I was not a big help, I'm learning just as everybody else is :)

0
Thxs jeterhipobunbun -7 — 6y
0
No problem, glad I could help! MrBlockyhead 84 — 6y
Ad

Answer this question