So I have this code that client sided, that gives you a money tool depending on the money you put it, but I need it give the money value to the money tool, server sided, but im confused on how i would split this up, any help? Here is the script.
local currency = "Cash" -- Change this to the currency you want to use
local button = script.Parent
local setter = button.Parent.AmountBox
debounce = false
function chaching()
button.Image = "http://www.roblox.com/asset/?id=96539788"
wait(1)
button.Image = "http://www.roblox.com/asset/?id=96539352"
end
function errormessage()
setter.ErrorText1.Visible = true
wait(3)
setter.ErrorText1.Visible = false
end
function notenough()
setter.ErrorText2.Visible = true
wait(3)
setter.ErrorText2.Visible = false
end
function onClick()
if debounce == false then
local player = button.Parent.Parent.Parent.Parent
if tonumber(setter.Text) and tonumber(setter.Text) % 1 == 0 and tonumber(setter.Text) >= 1 then
local amount = setter.Text
local cash = player.leaderstats:FindFirstChild(currency)
if tonumber(amount) <= cash.Value or tonumber(amount) == cash.Value then
cash.Value = cash.Value - tonumber(amount)
wait()
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value
local bag = game.Lighting.Money:clone()
bag.Parent = player:FindFirstChild("Backpack")
bag.MoneyValue.Value = amount
debounce = true
spawn(chaching)
wait(5)
debounce = false
else
notenough()
end
else
errormessage()
end
end
end
button.MouseButton1Click:connect(onClick)
You would fire a RemoteEvent from the server sending the information on the MoneyValue and then you would do an OnClientEvent function and pass the money value as a parameter.
Alrighty. You should use a Remote Event, like @histo_rical said.
As well as this, you should not clone the tool on the client. As well, don’t use Lighting for your storage, use Replicated Storage.
When using remote events, always assume the data sent has been tampered with. Check if the player has enough cash on the server and the client. In the server, after the sanity checks, you can clone the Tool, but put a IntValue in it. You can change the IntValues Value to the cash that has been put in.
You can then view the IntValue in scripts in the tool.
--Client
local currency = "Cash" -- Change this to the currency you want to use
local button = script.Parent
local setter = button.Parent.AmountBox
debounce = false
function chaching()
button.Image = "http://www.roblox.com/asset/?id=96539788"
wait(1)
button.Image = "http://www.roblox.com/asset/?id=96539352"
end
function errormessage()
setter.ErrorText1.Visible = true
wait(3)
setter.ErrorText1.Visible = false
end
function notenough()
setter.ErrorText2.Visible = true
wait(3)
setter.ErrorText2.Visible = false
end
function onClick()
if debounce == false then
local player = button.Parent.Parent.Parent.Parent
if tonumber(setter.Text) and tonumber(setter.Text) <= player.leaderstats.Cash.Value then
local amount = setter.Text
local cash = player.leaderstats:FindFirstChild(currency)
if tonumber(amount) <= cash.Value or tonumber(amount) == cash.Value then
game:GetService("ReplicatedStorage").Remo te:FireServer(tonumber(amount))
else
notenough()
end
else
errormessage()
end
end
end
button.MouseButton1Click:connect(onClick)
--Server
game:GetService("ReplicatedStorage").Remote. OnServerEvent:Connect(function(player,rcash)
if rcash > player.leaderstats.Cash.Value then return end
local tool = game:GetService("ReplicatedStorage").Tool:Clone()
tool.Parent = player.Backpack
tool.CashValue.Value = rcash
end)
Btw, you don’t need to use game:GetService(). Its just a personal preference of mine when writing code.