Need Help With Adding Currency When a Sword Swings

Need Help With Adding Currency When a Sword Swings
So I have a script which is featured down below that is activated everytime a player swing there weapon, it gives them Crowns and Gems. Well the thing for the gems I wanted them to be a more premium currency, meaning that only like 1-10 times you swing the sword you gain gems. Not everytime you swing the sword. How would I go about doing this?

SCRIPT
To break down the script there is a script in the tool, everytime the player clicks the screen the game waits one second before firing a remote event, this script calls the remote event, and when the remote event is activated this script activates giving the player +1 value to the players leaderstats.

local remote = game.ReplicatedStorage.Give

remote.OnServerEvent:Connect(function(Player)
	local plr = Player
	plr.leaderstats.Crowns.Value = plr.leaderstats.Crowns.Value +1
end)

local remote = game.ReplicatedStorage.Give

remote.OnServerEvent:Connect(function(Player)
	local plr = Player
	plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value +1
end)
2 Likes

so remote event is a nono because exploiters can just fire the remote like this ( while wait() do game.ReplicatedStorage.Give:FireServer()) this will cause exploiters to get infinite coins, so the best way is to put a script in a tool and dont do anything on a local script inside the tool,
so what you are going to do is putting a script in a tool then you have to detect when the player equips the tool and if activated u do a function that says plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value +1 and also dont forget to detect if the player unequipped the tool, if you need more help let me know

Yes I did that, this script isn’t in the tool this script is just in the workspace, as a function. When the player equips the tool the script is woken up, then there is another script in the tool that detects when the player clicks for the weapon. When the weapon is clicked a remote event fires to this script in the workspace that is a SERVER SCRIPT. This script then gives the player currency over the server, not through a local script, I may not script much, but I’m not a idiot.

What I’m trying to figure out is how to slow the addition of gems to the players leaderstats.

what do you mean the addition of gems, if you mean a wait u can do wait(1)

oh ya and also wdym, by fires to this script, dont do a fireserver basically do everything in serverscript, if you want to add particles when you swing dont put it on the server, you fireclient from the serverscript and do the stuff there

By the addition of gems I mean my secondary currency, which I referred to in my post. I can’t do a wait because the server script is firing from one remote event, so if I were to do a wait the script would not function for my primary currency “Crowns”, and everything I’m doing is server side, No exploiters will breach my game.

you dont need remote for a addition currency just under that currency you are giving in serverscript
do it under that line

I’m not understanding, can you alaborate?

sure send me the server script in messages and i will revise it for you

Tool Scripts

Detector

script.Parent.Unequipped:Connect(function()
	script.Parent.LocalScript.Disabled = true
end)

script.Parent.Equipped:Connect(function()
	script.Parent.LocalScript.Disabled = false
end)

Remote Caller

local remote = game.ReplicatedStorage.Give

script.Parent.Equipped:Connect(function()
	if script.Parent.Equipped then
				game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
				local plr = game.Players.LocalPlayer
				script.Disabled = true
				remote:FireServer()
        		for i = 1, 10 do
            		wait(0.010)
            	end
        		wait(.5)
        		for i = 1, 10 do
            		wait(0.010)
				end
				script.Disabled = false
			end)
		end
	end)

Workspace Function

local remote = game.ReplicatedStorage.GiveCrowns

remote.OnServerEvent:Connect(function(Player)
	local plr = Player
	plr.leaderstats.Crowns.Value = plr.leaderstats.Crowns.Value +1
end)

remote.OnServerEvent:Connect(function(Player)
	local plr = Player
	plr.leaderstats.Gems.Value = plr.leaderstats.Gems.Value +1
end)

FIGURE IT OUT MYSELF, Just disabled the script for 20, then rewoke

no dont i will send you a better one

1 Like

Instead of making a thread on this, just search it on youtube, this saves a lot of space on the dev forum for ideas that aren’t already covered, I am pretty sure there are at least a few tutorials on this subject.

yeah well i did and it doesn’t solve my problem

Fine
30 chahhharractorsdadadaddad

i already sent it but i deleted it since you said it is solved