Alright basically I’m working on a magic game and the magic skills are tools. Once the player uses a skill, it’s supposed to give the player a little bit of EXP and then they would need to wait until the cooldown on their skill is done so they can use that move again to gain more EXP. However my local script would give EXP every click and I don’t know how to fix it.
Here’s the full local script:
local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local Camera = workspace.Camera
local Mouse = player:GetMouse()
local tool = script.Parent
local AnimationsFolder = tool:WaitForChild("AnimationsFolder")
local Remotes = tool.Remotes
local CanAttack = tool:WaitForChild("CanAttack")
local SwordOut = tool:WaitForChild("SwordOut")
local Exp_1 = false
tool.Equipped:Connect(function()
Remotes:WaitForChild("SkillEqRE"):FireServer(tool,true)
end)
tool.Unequipped:Connect(function()
Remotes:WaitForChild("SkillEqRE"):FireServer(tool,false)
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Events:WaitForChild("AddExp")
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
spawn(function()
Exp_1 = true
Exp_1 = Remotes:WaitForChild("AddExp"):InvokeServer()
end)
end
end)
end)
Main problem is here:
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
spawn(function()
Exp_1 = true
Exp_1 = Remotes:WaitForChild("AddExp"):InvokeServer()
end)
end
end)
end)
It basically invokes an event every click and I need to fix this.