So, I made this currency system for my weird (secret) game.
As all questions of me, Not even ONE of these gets answered.
I will explain how it works.
First, a local script in a frame will fireserver() on a script in ServerScriptService. That script will pick it up and convert a currency to another currency. This is the serverscript:
local PER = game.Workspace.ShopGuiRemotes:WaitForChild("ChangePercent")
local EXCHANGECUR = game.Workspace.ShopGuiRemotes:WaitForChild("ExchangeCurrencies")
PER.OnServerEvent:Connect(function(plr, default, textbox)
local GUI = plr.PlayerGui.CurrencyExchange
local TEXTBOX = textbox
if TEXTBOX then
print("Percent exeeding limit")
TEXTBOX.Text = default
repeat wait() TEXTBOX.Text = default until TEXTBOX.Text == default
end
end)
EXCHANGECUR.OnServerEvent:Connect(function(PLR,CUR1,CUR1M,CUR2,CUR2M,EXCHANGEPER)
local LEADER = PLR:WaitForChild("leaderstats")
local CUR1 = LEADER:FindFirstChild(CUR1)
local CUR2 = LEADER:FindFirstChild(CUR2)
if not CUR1 or not CUR2 or not LEADER then
if not CUR1 and not CUR2 then
local CUR1 = PLR:FindFirstChild(CUR1)
local CUR2 = PLR:FindFirstChild(CUR2)
end
if not CUR1 then
local CUR1 = PLR:FindFirstChild(CUR1)
elseif not CUR2 then
local CUR2 = PLR:FindFirstChild(CUR2)
end
end
if CUR1 and CUR2 then
local CUR1V = CUR1.Value
local CUR2V = CUR2.Value
local REPCOUNT = (math.floor(CUR1V/CUR1M)*EXCHANGEPER)/100
print(REPCOUNT)
for i = 1, REPCOUNT do
CUR1.Value = CUR1.Value - CUR1M
CUR2.Value = CUR2.Value + CUR2M
end
end
end)
What the script does (On line 28) is it gets the two currencies (CUR1 AND CUR2) and it also gets the rate of the currencies. (CUR1M, CUR2M) Example: trade CUR1M CUR1 for CUR2M CUR2.
What i mean by that is: Trade [Number of CURRENCY 1] [CURRENCY1] for [Number of CURRENCY2] [CURRENCY2].
And EXCHANGEPER? That is the percentage you want to trade CUR1 for. Example: Only trade 20% of all the CUR1 in LEADERSTATS.
Here is the local script:
local EC = script.Parent:WaitForChild("ExchangeCurrencies")
local PLR = game.Players.LocalPlayer
local LEADER = PLR:WaitForChild("leaderstats")
local EXCHANGEPER
local EXCHANGEPERGUI = script.Parent:WaitForChild("CPercent")
local CHANGEPERREM = game.Workspace.ShopGuiRemotes.ChangePercent
local EXCHANGEREM = game.Workspace.ShopGuiRemotes.ExchangeCurrencies
local EXCHANGEBUTTONS = script.Parent.ExchangeCurrencies
local DEFPER = 20
local EXCHANGEPER = DEFPER
local SHOWED = true
script.Parent:TweenPosition(UDim2.new(0.36, 0,2, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Bounce,1,true)
EXCHANGEPERGUI:GetPropertyChangedSignal("Text"):Connect(function()
if tonumber(EXCHANGEPERGUI.Text) then
EXCHANGEPER = tonumber(EXCHANGEPERGUI.Text)
if EXCHANGEPER > 100 or EXCHANGEPER < 1 then
-- CHANGEPERREM:FireServer(DEFPER, EXCHANGEPERGUI)
EXCHANGEPERGUI.Text = DEFPER
EXCHANGEPER = DEFPER
return false
end
EXCHANGEPER = tonumber(EXCHANGEPERGUI.Text)
else
EXCHANGEPERGUI.Text = ""
end
end)
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
if not SHOWED then
SHOWED = true
script.Parent:TweenPosition(UDim2.new(0.36, 0,0.219, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Bounce,1,true)
elseif SHOWED then
SHOWED = false
script.Parent:TweenPosition(UDim2.new(0.36, 0,2, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Bounce,1,true)
end
end)
EXCHANGEBUTTONS["1"].MouseButton1Click:Connect(function()
EXCHANGEREM:FireServer("Multiplier",1000,"UL. Multiplier",1,EXCHANGEPER)
end)
EXCHANGEBUTTONS["2"].MouseButton1Click:Connect(function()
EXCHANGEREM:FireServer("UL. Multiplier",10,"Multiplier",10000,EXCHANGEPER)
end)
EXCHANGEBUTTONS["3"].MouseButton1Click:Connect(function()
EXCHANGEREM:FireServer("Points",100,"XP",1,EXCHANGEPER)
end)
EXCHANGEBUTTONS["4"].MouseButton1Click:Connect(function()
EXCHANGEREM:FireServer("XP",10,"Points",1000,EXCHANGEPER)
end)
EXCHANGEBUTTONS["5"].MouseButton1Click:Connect(function()
EXCHANGEREM:FireServer("XP",100,"Damage",1,EXCHANGEPER)
end)
EXCHANGEBUTTONS["6"].MouseButton1Click:Connect(function()
EXCHANGEREM:FireServer("XP",1000,"Health",1,EXCHANGEPER)
en
The problem begins when i press the 5TH button. The masterscript (In ServerScriptService) Errors out and says:
Argument 1 missing or nil
10:54:17.126 - Stack Begin
10:54:17.126 - Script 'ServerScriptService.Masterscript', Line 25
10:54:17.126 - Stack End
I CLEARLY defined CUR2 in the local masterscript.
Any of you who can fix this? I really need this system for my game.
PS: I put extra checks so that the script does not stop working. Beggining from line 17 and ending at line 27. Maybe thats the problem?
