Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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 :)

2 comments

0

Thxs

0

No problem, glad I could help!

This discussion is preserved as it was. New answers, comments, and votes are closed.