Hello I am creating a ability system which does something after a key is pressed however it prints the output 5 times and fires the event five times.
The local script is inside the character model disabled then enables once spawning as the character and this is the only place where it is.
Here is the Local script:
> --Basic Witch Abilities
>
> --Telekinetic Push
> task.spawn(function()
> local UIS = game:GetService("UserInputService")
> local Cooldown = 20
> local Debounce = false
> local Player = game.Players.LocalPlayer
> local Character = Player.Character
> local Mouse = Player:GetMouse()
>
> UIS.InputBegan:Connect(function(key, IsTyping)
> if key.KeyCode == Enum.KeyCode.C then
> if not IsTyping then
> if Mouse.Target.Parent:FindFirstChildWhichIsA("Humanoid") then
> if (Mouse.Target.Parent.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude < 10 then
> if Debounce == false then
> Debounce = true
> print(Mouse.Target.Parent)
> game.ReplicatedStorage.Remotes.Abilities:FireServer("Basic Telekinetic Push", Mouse.Target.Parent)
> wait(Cooldown)
> Debounce = false
> end
> else
> if Debounce == true then
> print(Cooldown)
> end
> end
> else
> if (Mouse.Target.Parent.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude > 10 then
> print("To far from Target")
> end
> end
> end
> end
> end)
> end)
This is the output: