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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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!

0
but I need to see the text because the text is to show how many you have JohnerDev 27 — 5y
0
wait nvm JohnerDev 27 — 5y
0
i still need some help though JohnerDev 27 — 5y
0
With? I'm a bit confused now... JackOfAllBlox 32 — 5y
View all comments (9 more)
0
well i feel like i messed up the first part local cash = game:GetService("Players"):WaitForChild("leaderstats"):WaitForChild("Cash") JohnerDev 27 — 5y
0
and script.Parent.Parent.ImageLabel.TextLabel = script.Parent.Parent.ImageLabel.TextLabel.Text + 1 JohnerDev 27 — 5y
0
because i don't think you can add to text and i dont know how to fix that JohnerDev 27 — 5y
0
Do you want to see what i'm making? JohnerDev 27 — 5y
0
i fixed the local cash = game:GetService("Players"):WaitForChild("leaderstats"):WaitForChild("Cash") JohnerDev 27 — 5y
0
and replaced with local cash = game.Players.LocalPlayer:WaitForChild("leaderstats").Cash.Value and local stock = game.Players.LocalPlayer:WaitForChild("Stocks").ONE.Value JohnerDev 27 — 5y
0
Players.johner2000.PlayerGui.CashNStuff.Frame.Investments.TextButton.LocalScript:6: attempt to perform arithmetic on upvalue 'stock' (a boolean value) whats this mean? JohnerDev 27 — 5y
0
BTW thank you for trying to help! JohnerDev 27 — 5y
0
It means you can't add numbers with true or false (boolean) joshthegamer456 93 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

0
Still confused JohnerDev 27 — 5y
0
well i have to go for now cya tommorow maybe... JohnerDev 27 — 5y

Answer this question