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

Can anyone help? I am really confused. My shop gui doesn't work.

Asked by 4 years ago
Edited 4 years ago

Can anyone please solve this, it is in startergui then shop (a screen gui) , then frame, then main (a frame) then item 1 (contains script with code 1), item 2 (contains script with code 2), a serperator ( a frame), a textbutton, and a title. script 3 is in the workspace.

1. script.Parent.MouseButton1Click:connect(function()
 local RS = game:GetService("ReplicatedStorage")
 local item =  RS:WaitForChild("Sword")
 local price = 100
 local player = game.Players.LocalPlayer
 local stats = player:WaitForChild("leaderstats")

 if stats.Cash.Value == price then 
  stats.Cash.Value = stats.Cash.Value - price
  local cloned = item:Clone()
  local cloned2 = item:Clone()
  cloned2.Parent = player.Backpack
  cloned.Parent = player.StarterGear
 end
end)
2. script.Parent.MouseButton1Click:connect(function()
 local RS = game:GetService("ReplicatedStorage")
 local item =  RS:WaitForChild("Rocket Launcher")
 local price = 500
 local player = game.Players.LocalPlayer
 local stats = player:WaitForChild("leaderstats")

 if stats.Cash.Value == price then 
  stats.Cash.Value = stats.Cash.Value - price
  local cloned = item:Clone()
  local cloned2 = item:Clone()
  cloned2.Parent = player.Backpack
  cloned.Parent = player.StarterGear
 end
end)


3. print("Hello world!") game.Players.ChildAdded:connect(function(player) local stats = Instance.new("Model",player) stats.Name="leaderstats" local money = Instance.new("IntValue",stats) money.Name="Cash" money.Value=30 -- Change Your Starting Money end)
2
Please make your code into script format using lua button because it is hard to read. Yuuwa0519 197 — 4y
0
Yuwa I have already did that it started out with that amount of cash but still it didn't work RamenRobloxian 2 — 4y
0
How about the `if player.Cash.Value == price then` part? Also, since the gui works on client(local script), you have to learn how to use remote events so you can actually change cash of player and give items. Yuuwa0519 197 — 4y
0
Okay thanks I will try it. Sorry I am new to the forum. RamenRobloxian 2 — 4y
1
So you want us to read all the 3 scripts and then guess where is the problem? Please at least read the output and tell us where is the problem, or if no error message, then tell what's wrong.. Miniller 562 — 4y

1 answer

Log in to vote
0
Answered by
Yuuwa0519 197
4 years ago
Edited 4 years ago

I don't know if you are going to be able to obtain more cash in game, but currently your default money seems not enough to purchase any of those items. If that is the case, make default cash more higher or make a system to give yourself more cash so you can have enough cash to buy item.

The error I found in the script is that I think you can't buy a item even if you have more money than it's price. That is because you are using if stats.Cash.Value == price then which checks if you have exact same amount of money as price, then purchase instead of checking if you have more cash than the price of item. All you need to do is to replace " ==" (equal to) to ">=" (greater than, or equal to) so you can buy the item if you have same or more cash than price.

Ad

Answer this question