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

This script for a Shop GUI works in Studio, but not in game??

Today I made a Shop GUI. It opens in studio, but in game it doesn't open no matter how many times I click. Any help? (I used a LocalScript fyi)

repeat wait()
	Player = game.Players.LocalPlayer
Button = script.Parent
Item = game.ReplicatedStorage:FindFirstChild("GravityCoil")
Cost = 50
Money = Player.leaderstats.Money	
until

Button.MouseButton1Down:connect(function(purchase)
	if Money.Value > (Cost - 1) then
		Money.Value = Money.Value - Cost 
		local a = Item:Clone()
		a.Parent = Player.Backpack
		local b = Item:Clone()
		b.Parent = Player.StarterGear
	end
end)

2 comments

0

What doesn't it do?

0

The shop doesn't open when I click on the shop button.

1 answer

✓ Accepted answer

I believe your problem is that you're not letting everything load in quick enough for it to work properly in the script.

Try this:

repeat wait()
	Player = game.Players.LocalPlayer
	Button = script.Parent
	Item = game.ReplicatedStorage:WaitForChild("GravityCoil") --Method of waiting for it to load in
	Cost = 50
	repeat wait() until Player.leaderstats --Different method of waiting for them to load in
	repeat wait() until Player.leaderstats.Money
	Money = Player.leaderstats.Money    
until

Button.MouseButton1Down:connect(function(purchase)
	if Money.Value > (Cost - 1) then
		Money.Value = Money.Value - Cost 
		local a = Item:Clone()
		a.Parent = Player.Backpack
		local b = Item:Clone()
		b.Parent = Player.StarterGear
	end
end)

Anyways, I believe the script should work now if everything else is correct the way it is.


Hope this helped, and if you have any further problems/questions, please leave a comment below :P

####-Dyler3

8 comments

0

He used this video to help him i'm pretty positive; https://www.youtube.com/watch?v=Hcve7MHeGLc. So, it should work if he copied the script there.

0

Still isnt working, idk why

0

I did, it works in studio, but not in a server

0

Well if this is the case, it should actually work perfectly fine. Adding in this wouldn't hurt however. Just make sure that all of the names and everything are correct, and that everything is where it's supposed to be.

0

Wanna see the place I'm talking about? :3

0

Sure

0

ty dyler!!

0

No prob :P

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