Money Exchanger not working (Repost)

[REPOST] bc the old post is too old so people didn’t notice, and no solution for the old post yet.

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)

all helps are appreciated.

1 Like

Any errors, did u try printing? Please give us more information about your problem.

1 Like

I tried using print() to find where it stops, it doesn’t print
and it seems like it doesn’t show any error at all, yes I already looked at the output

it exchanges research points using cash, 1 cash = 2 research points (the script shows 5 but i changed it)

1 Like

So it stops at the MouseButton1Click Event?

Oh, Idk, but it seems to be yes

Is this Local Script? You can not perform any changes for server on client side.

i tried to use ServerScript, it doesn’t work so I switched to LocalScript but it doesn’t work too

You must use RemoteEvents if you want it to work via server.

3 Likes

I tried that too, but didn’t work

Ohh lord… :smile: so… what you want to do is simple:

  1. You will create RemoteFunction/Event
  2. Call the Event from the Client
  3. Check and exchange the value in Server Script
2 Likes

I already solved someone’s problem with similiar issue.

2 Likes

Yeah like @ProBaturay said you should probably do this using RemoteEvents.

-- Client | LocalScript
local Event = -- Define RemoteEvent here
local Button = script.Parent

Button.Activated:Connect(function() -- You can use :MouseButton1Down if you want
   Event:FireServer(script.Parent.Parent.Value)
end)

-- Server Script
local Event = -- Define it here

Event.OnServerEvent:Connect(function(player, fundsVal)
  if Player.Data.CashValue.Value >= fundsVal then
     -- Do whatever you need to here
  end
end)
3 Likes

thanks, y’all. Finally made some RemoteEvent script to work! :smiley:

No problem I am glad that we helped you!:grinning::+1:

1 Like