Hello again! Today I’m making a cash exchanger (like Cash to Gems)
but it doesn’t work…
here’s the script:
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local Data = plr:WaitForChild("Data")
local Currency = Data.Currency
local CashValue = Currency.CashValue
local ResearchPoints = Currency.ResearchPoints
local Funds = script.Parent -- Button
local Int = Funds.Parent.Value -- IntValue
Funds.MouseButton1Click:Connect(function()
if CashValue.Value >= Int.Value then
CashValue.Value = CashValue.Value - Int.Value
ResearchPoints.Value = ResearchPoints.Value + Int.Value * 5
end
end)
I don’tthink you need the GetPropertyChangedSignal event i nthe Mousebutton1Click event for this. Also, I recommend you try to convert the text to a number first and then do the conversion. Also Amount.Value is going to error since Textboxs don’t have the Value property, try this out?
Funds.MouseButton1Click:Connect(function()
local convertAmount = tonumber(Amount.Text)
if not convertAmount then return end --Text wasn't a number
if Cash.Value >= convertAmount then
Cash.Value -= convertAmount
ResearchPoints.Value += (convertAmount * 5)
end
end)
Also not sure if you forgot to put .Value after Cash since I’m not sure if it’s a BaseValue or not
Try adding print statements to see where it is stopping? And try printing convertAmount after setting it. It should work, somewhere in there it is stopping
The only way to do this is by detecting mouse clicks on the client and doing everything else on the server as the client cannot be trusted. See my previous reply for an example and make sure that you are doing it right.
The only major error I see is that you are trying to check if Cash >= String, which won’t work.
Try this instead, since you need to compare it with an int:
if Cash >= tonumber(Amount.Text) then
if Amount.Value is a string as well, use tonumber as shown above.
Also, your second function (Amount:GetPropertyChangedSignal("Text")) shouldn’t be inside of your MouseButton1Click event as it will only fire once the player fires the first event.
Also, I don’t see why you are doing this client-sided as it won’t replicate (update) on the server-side.
And if you plan to switch to a RemoteEvent, DO NOT check the cash amount on the client as exploiters can have a fun time if that’s the case.