So I’m currently working on a currency system and I’ve struck a problem on how to make a cash item if you would click would give you money.
So I made this GUI for reference where whenever you click the text button it fires a remote event which gives you cash to your leaderstats
So to sum it all up I’ve got no clue on how to make a clickdetector cash part that gives money whenever its clicked by a player.
Sorry if I explained this a bit badly, not really sure how to explain it
Heres the gui that gives money whenever its clicked
local remote = game:GetService("ReplicatedStorage").CurrencyRemote.GiveCurrency
local amount = 20
script.Parent.Activated:Connect(function()
remote:FireServer((amount))
end)
Code for local script:
local button = script.Parent
local remote = game:GetService("ReplicatedStorage").CurrencyRemote.GiveCurrency
local amount = 20
button.MouseButton1Click:Connect(function()
remote:FireServer(amount)
end)
Place a normal script in the ServerScriptService
Here’s the code for the normal script:
local remote = game:GetService("ReplicatedStorage").CurrencyRemote.GiveCurrency
remote.OnServerEvent:Connect(function(player, amount)
local leaderstats = player:WaitForChild("leaderstats")
local currency = leaderstats:WaitForChild("")------ currency name
currency.Value = currency.Value + amount
end)
Let me know if you have problems!
1 Like
Don’t think its right, definitely because the way I explained my situation.
So i have this part with a clickdetector. and I want to make it so whenever you click it, it would give you cash.
used the code i posted as like an example or something, pretty sure thats what threw it off
So basically the code i sent was a gui to test giving money to the leaderstats
Place this in a part with a click detector.
local clickDetector = script.Parent:WaitForChild("ClickDetector")
local amount = 20
clickDetector.MouseClick:Connect(function(player)
if game.Players:FindFirstChild(player.Name) then
local leaderstats = player:WaitForChild("leaderstats")
local currency = leaderstats:WaitForChild("")---- name of currency
currency.Value += amount
end
end)
1 Like
Isn’t working for some reason. Do you wanna see the leaderstats code maybe?
Did you place the code in a normal script? If not, change it to a normal script. Then place it in the part you want to click.
1 Like
oohhh wait let me try that, so sorry
Its working, thank you so much. Also if i want to make it so when you click it and it removes itself do i just put Cash.Destroy()
Do you mean deleting the part you want to click? If yes, then you should put: script.Parent:Destroy()
1 Like
yeah, thats what i mean’t. Thank you so much for the help!
1 Like