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

Buy an item in a shop?

Can you please help me with a script that buys an item off the leaderstats?

1 comment

0

This question makes no sense.

2 answers

✓ Accepted answer

Hello, I agree with Bubbaman73, But instead of just answering this question I can help you understand how to do it so you do not have confusion again!

So, lets open up our Studio. Now, theres two ways you can go about this :

1 . You can make a Humanoid and and create a touch() GUI. 2 . You can make a GUI they can click and a Shop will open up.

I will teach you #2 since it is most commonly used.

First thing I am going to have you do is go to StarterGUI > Insert ScreenGUI. [Rename it ShopGUI] Then, right click your ScreenGUI > Insert Frame. Rename the Frame to "Open".

NOTE : I am only here to help you on the Scripting so you will have to remodel and reaize the GUI's how you want them to be!

Now this first OpenFrame will be the GUI they see on their screen to click so they can open access to the In-Game Shop. Inside of the OpenFrame > Insert Text Button ; Rename to "Open" again.

Inside of this Open Text button, Insert a Script [NOT LOCAL] , You are going to want to insert this coding :

print("Close button loaded")

window = script.Parent.Parent

function onClicked(GUI)
window.Visible = false
window.Parent.Shop.Visible = true




end
script.Parent.MouseButton1Click:connect(onClicked)

Once you have done, we are finished with our Open Section. You can now minimize it. Now go back and right click your OpenGUI > Insert Frame again. Rename this one to "Shop"

We will now be creating the shop. This can get a little bit confusing if this is your first time, so make sure to pay close attention!

First thing you are going to want to do is right click your ShopFrame > Insert TextButton. Rename this TextButton to "Close"

This will be our Closing button to dismiss the ShopGUI. Right click on your CloseButton > Insert Script.

Insert this coding :

print("Close button loaded")

window = script.Parent.Parent

function onClicked(GUI)
window.Visible = false
window.Parent.Open.Visible = true




end
script.Parent.MouseButton1Click:connect(onClicked)

Next, right click on your ShopFrame again and Insert another TextButton. Rename the second one to "Item1".

Now, I will help you put one item in, you can repeat the process to add in more items if you like. For your Item1 ; Insert two Scripts and rename one "Buy" and the other "Confirmed"

NOW, for Item1, just as an example, lets use a MedKit for our item. Where you see "MedKit" in this Script just replace to the EXACT name you have your item in Lighting.

Put this coding into the Buy Script : [Where you see price = , you can also change how much you want them to buy it for.

player = script.Parent.Parent.Parent.Parent.Parent
money = player.leaderstats.KOs
price = 5
tool = game.ServerStorage:findFirstChild("MedKit")

function buy()
if money.Value >= price then
local a = tool:clone()
a.Parent = player.Backpack
local b = tool:clone()
b.Parent = player.StarterGear
end
end
script.Parent.MouseButton1Down:connect(buy)

Put this coding into the Confirmed Script :

function buy()
script.Disabled = true
script.Parent.Buy.Disabled = false
end

script.Parent.MouseButton1Down:connect

REMINDER : YOU MUST HAVE THE ITEMS WITH THE EXACT NAME IN LIGTING OR IT WILL NOT WORK.

Repeat Item1 process to add in more items. I hope this helps! (:

Sorry i would have wrote this in the comments box but i could not seem to find it. If you have not tried anything; This is not a request site. If you have, please show us your script.

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