[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)
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)