So i want to do when the player has 1500 points, when a button is clicked it checks the amount of points the player has then it runs some code and it takes away some points as well, because you bought something and that's basically how Shop Scripts work.
I put this script in a GUI in a TextButton
: (In a LocalScript
)
local points = script.Parent.Parent.Parent.Parent.ShopMenu.PlayerPoints.num script.Parent.MouseButton1Click:Connect(function() if tostring(points.Text >= 1500) then points.Text = tostring(tonumber(points.Text) - 1500) workspace.PlanetPlacement.BillboardGui.Enabled = true workspace.Planet.PlanetBall.BillboardGui.Enabled = true workspace.PlanetPlacement2.BillboardGui.Enabled = true workspace.PlanetPlacement3.BillboardGui.Enabled = true end end)
I want to do another if then
statement (if tostring(points.Text) <= 1500 then
for short) for when your currency is less than 1500, running code saying that your balance is low.
This is what i tried: (In a LocalScript
)
local points = script.Parent.Parent.Parent.Parent.ShopMenu.PlayerPoints.num script.Parent.MouseButton1Click:Connect(function() -- ^ other if then statement above (not the function) -- if tostring(points.Text <= 1500) then print("Balance Low. Needs " ..points.Text - 1500.. " more points to buy.") --This can be a TextLabel as well. wut ever if that's wrong just fix it plz! :P (and delete this comment) script.Parent.Parent.PurchaseFailedTXT.Visible = true end end)
And the points GUI code: (the variable on line 1 of all of the code above [In a LocalScript
])
local pointsToEarn = 35 local waitTime = 1 while wait(waitTime) do script.Parent.Text = script.Parent.Text + pointsToEarn end
Plx help me with my issues! Thx! ~Chez_Guy ;)
You should probably, in my opinion, do something like this for storing an amount of points.
local valofpoints = Instance.new("NumberValue",game.Players.ExamplePlayer) valofpoints.Value = 0 -- starting point value
It can easily be accessed by LocalPlayer. Just a tip. And for the GUI points code;
while wait(waitTime) do valofpoints = valofpoints + pointsToEarn pointsToEarn = script.Parent.Text end
Because when you do something like what you did for points GUI, this happens. -- Take 2 me; Realized that's not what you did, oops lol Anyway, what you did wrong was the fact that the text needs to be set to 0 beforehand. BUT, the way I did, I don't think there would be a problem. valofpoints would have part of it removed, therefore changing the value, which would probably fix the stuff. You should probably try that.