Hi! So, I installed a shop system, and it originally worked. After implementing a use for it, though, the price stopped changing. I don’t know why! It was originally working, but all of a sudden it just stopped. Please help!
Script
--buyScript (LocalScript)
local RepStorage = game:GetService("ReplicatedStorage")
local BuyTimeEvent = RepStorage:WaitForChild("BuyTimeEvent")
script.Parent.MouseButton1Click:Connect(function()
BuyTimeEvent:FireServer()
end)
--BuyTimeScript (Script)
local RepStorage = game:GetService("ReplicatedStorage")
local SStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local TimePrice = SStorage:WaitForChild("TimePrice")
local TimePriceLabel = StarterGui.BuyTime:WaitForChild("TimePriceLabel")
local BuyTimeEvent = RepStorage:WaitForChild("BuyTimeEvent")
local module = require(RepStorage:WaitForChild("ModuleScript"))
BuyTimeEvent.OnServerEvent:Connect(function(player)
local leaderstats = player.leaderstats
local cornStat = leaderstats:WaitForChild("corn")
local timeupgStat = leaderstats:WaitForChild("timeupg")
if cornStat.Value >= TimePrice.Value then
cornStat.Value = cornStat.Value - TimePrice.Value
TimePrice.Value = TimePrice.Value + TimePrice.Value * 0.1
timeupgStat.Value = timeupgStat.Value + 1
TimePriceLabel.Text = tostring(TimePrice.Value) .. " Corn"
module.waitTime = (module.waitTime * 0.1 - module.waitTime) * -1
print(module.waitTime)
else
print("broke")
end
end)
Does “Broke” get outputted? If so, then the issue is that your corn is less than time price. You need to increase corn is fix this issue.
If broke is not outputted, then the issue might TimePrice.Value. Is it a number object or an int object? If it is an int object, then what could be happening is that if TimePrice is equal to 1, your code does 1 + 1 * 0.1, which is equal to 1.1. However since TimePrice is an int object, it could be rounding down the number. This causes it to be set back to 1, which results in no change in price.
The fix is to change TimePrice to a number value object. Int only allows for whole numbers, while number allows for decimal.
Note: I could not find info on what happens when you attempt to set a decimal number to a IntValue object. However in other languages it usually rounds down or up.
There’s a textlabel on my shop board, and it says something like “100 Corn”
When you buy it, it should change to something like “110 Corn”
Buy it again, it says “121 Corn”
and so on…
Your calculation is wrong here (BODMAS applied here, multiplication goes first). So it should be: 100 + 100 * 0.1, which is the same as 100 + (100 * 0.1). This results In 110.
Based on the code, TimePrice appears to be the price of something that you pay with corn. So “100 Corn” is 100 TimePrice. CornStat on the other hand appears to be how much corn the player has.
In other words, CornStat is like player cash while TimePrice is the price of an item. The price of the item increases after each purchase (by 10%, hence the *0.1).
(This is a guess as to what the code is trying to do)
What you need to do is store the players corn stat and time price on the server (I suggest using tables here)
When BuyTimeEvent is triggered, you will need to update the players corn stat and time price on the server script.
Then the server script will need to “fire” to a remote event to update the clients GUI (In the parameters you need to include the new corn stat and total price).
Then in the local script you will need to “listen”/set up OnClientEvent for that same remote event. This will then receive the new corn stat and time price.
Finally you set the time price label (and corn stat label if you have one).
I understand the order of operation, but the reason I put () around 110+100 is it equals 2.1. Since to get from 100 → 110 they added 10 corn. So what I think happened was they this (110+100)*.1 then multiplied by 100 to get 21. Then added it to 100. So 100+21 → 121 Corn
.OnClientEvent the first parameter will not be player it will be TimePrice. The reason you have player in ur server script is that the server needs to know what client/player to send the data. So ur local script should say