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

How do I allow a person to buy this from a GUI/shop?

I tried to do this it didn't work so I believe that I did something wrong. (Yes its a local script.)

local stock = game.Players.LocalPlayer:WaitForChild("Stocks").ONE.Value
local cash = game.Players.LocalPlayer:WaitForChild("leaderstats").Cash.Value
local OPrice = game.Workspace.ONEVal.ONEPrice
local a = game.StarterGui.CashNStuff.Frame.Investments.Buy1
 
local stock = tonumber(a.Text)
a.Text = tostring(stock)
script.Parent.MouseButton1Click:connect(function()
  if cash > OPrice.Value then 
	stock = stock + 1 and cash == cash - OPrice.value and a.Text == tostring(stock)
	else print("Not enough cash")
end
end)

UPDATED still error

2 answers

You can't compare an integer value to a string value which you do:

if cash == game.Workspace.Board.SurfaceGui.SmoothGUI.PriceONE.Text 

The cash is an integer (number), while the text is a string value. Possibly using an IntValue object and comparing cash to that, I would suggest using a > sign rather than = would work. Hope this helped!

13 comments

0

but I need to see the text because the text is to show how many you have

0

wait nvm

0

i still need some help though

0

With? I'm a bit confused now...

0

well i feel like i messed up the first part local cash = game:GetService("Players"):WaitForChild("leaderstats"):WaitForChild("Cash")

0

and script.Parent.Parent.ImageLabel.TextLabel = script.Parent.Parent.ImageLabel.TextLabel.Text + 1

0

because i don't think you can add to text and i dont know how to fix that

0

Do you want to see what i'm making?

0

i fixed the local cash = game:GetService("Players"):WaitForChild("leaderstats"):WaitForChild("Cash")

0

and replaced with local cash = game.Players.LocalPlayer:WaitForChild("leaderstats").Cash.Value and local stock = game.Players.LocalPlayer:WaitForChild("Stocks").ONE.Value

0

Players.johner2000.PlayerGui.CashNStuff.Frame.Investments.TextButton.LocalScript:6: attempt to perform arithmetic on upvalue 'stock' (a boolean value) whats this mean?

0

BTW thank you for trying to help!

0

It means you can't add numbers with true or false (boolean)

Johner to fix your error that you commented under JackOfAllBlox's answer, you would use tostring() and tonumber(). This converts the stringvalue of the number to a number, and you could change it back to the string after performing the arithmetic. For example,

local a = game.StarterGui.ScreenGui.Frame.TextLabel.Text

local b = tonumber(a)
b = b + 1
a = tostring(b)

Edit: Actually that script would not work since I did TextLabel.Text I would have to do:

local a = game.StarterGui.ScreenGui.Frame.TextLabel

local b = tonumber(a.Text)
b = b + 1
a.Text = tostring(b)

2 comments

0

Still confused

0

well i have to go for now cya tommorow maybe...

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