Preventinig people to Spam a tool

Ok so i have a problem when someone Equip the tool on my stats it goes 1 per sec but
if someone spam the tool and after have t equiped it gived like 100 depends on how maney times you equiped and unequip spammed the tool

Script:

local player = game:GetService("Players"):WaitForChild(script.Parent.Parent.Parent.Name)
local meditating = false

script.Parent.Equipped:Connect(function()
	meditating = true

	while wait(1.5) do
		if meditating == true then
			player.PsychicPower.Value = player.PsychicPower.Value  + 1 * player.PPMulti.value*player.PPZoneMulti.Value
		end
	end
end)

script.Parent.Unequipped:Connect(function()
	meditating = false
end)

You would want to try cancel the loop

1 Like

So do something like:

local player = game:GetService("Players"):WaitForChild(script.Parent.Parent.Parent.Name)
local meditating = false

script.Parent.Equipped:Connect(function()
	meditating = true

	while wait(1.5) do
		if meditating == true then
			player.PsychicPower.Value = player.PsychicPower.Value  + 1 * player.PPMulti.value*player.PPZoneMulti.Value
   else
           break/return
          
		end
	end
end)

script.Parent.Unequipped:Connect(function()
	meditating = false
end)
1 Like

i wil try if that works else i wil tell you

1 Like

Nope not working it still keep multiplying itself

so in the code are you using break or return?

1 Like

yes i did mayby we need to find a way to stop them from spamming the tool

I mean just replace the break/return with return or break

1 Like

yes i did that but both dont work

Do you mind if i see your updated code again then?

local player = game:GetService(“Players”):WaitForChild(script.Parent.Parent.Parent.Name)
local meditating = false

script.Parent.Equipped:Connect(function()
meditating = true

while wait(1.5) do
	if meditating == true then
		player.PsychicPower.Value = player.PsychicPower.Value  + 1 * player.PPMulti.value*player.PPZoneMulti.Value
	else
		Break

	end
end

end)

script.Parent.Unequipped:Connect(function()
meditating = false
end)

Didint work and

local player = game:GetService(“Players”):WaitForChild(script.Parent.Parent.Parent.Name)
local meditating = false

script.Parent.Equipped:Connect(function()
meditating = true

while wait(1.5) do
	if meditating == true then
		player.PsychicPower.Value = player.PsychicPower.Value  + 1 * player.PPMulti.value*player.PPZoneMulti.Value
	else
		return

	end
end

end)

script.Parent.Unequipped:Connect(function()
meditating = false
end)

btw it a lowercase b for break

1 Like

What do you mean with that ???

so break not Break as you put Break which doesn’t work

2 Likes

ok now i am confused explain me more

local player = game:GetService("Players"):WaitForChild(script.Parent.Parent.Parent.Name)
local meditating = false

script.Parent.Equipped:Connect(function()
	meditating = true

	while wait(1.5) do
		if meditating == true then
			player.PsychicPower.Value = player.PsychicPower.Value  + 1 * player.PPMulti.value*player.PPZoneMulti.Value
   else
           break
          
		end
	end
end)

script.Parent.Unequipped:Connect(function()
	meditating = false
end)

there that it was it could look like
with a lowercase b for break

Tryed that still didint work any other ideas to fix

hmmmmm this is confusing as the while loop is constantly being called and not stopped meaning it duplicates the + 1 but a break or return should stop that

Where is the script located and why type of script is it?

its in the tool self and its a normal script