i made the same post again for people to see this and help me (hopefully)
i currently have a problem with my parry system, here’s the script:
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local block = hum:LoadAnimation(ReplicatedStorage.Assets.Animations.Block)
local mouse = player:GetMouse()
local DB = false
local istool = false
local parryre = ReplicatedStorage.Assets.Events.Parry
local rs = game:GetService("RunService")
local function onToolEquipped(tool)
UIS.InputBegan:Connect(function(input, gameprocessed)
if not gameprocessed then
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if istool then
if not DB then
DB = true
parryre:FireServer()
wait(2)
DB = false
end
end
end
end
end)
end
char.ChildAdded:Connect(function(newChild)
if newChild:IsA("Tool") then
istool = true
onToolEquipped(newChild)
end
end)
char.ChildRemoved:Connect(function()
istool = false
end)
the problem is a bit hard to explain but, to sum it up whenever i unequip a tool and spam the parry input. when i equip a tool again and parry again it spams the parry animation
here’s a video of the problem:
(sorry for the poor quality)
robloxapp-20240618-1254525.wmv (817.5 KB)
(i only pressed the parry input when i equipped the sword the first time and when i unequipped the sword)
I tried solving this myself but it ended up creating more problems so any help is appreciated.
thank you.
Instead making the parry input function inside the toolequipped function you can try
making the input function outside it, and using bool values to check if player can parry:
- onToolEquipped:
canParry = true
- onToolUnequipped:
canParry = false
or you can try using ContextActionService
From what I can see, the issue appears to be that you aren’t checking if the removed instance in the char.ChildRemoved event is the tool, so the tool unequips anytime anything is removed from the character. You should also disconnect connections that shouldn’t be listened for anymore, like the UIS.InputBegan connection you have.
local UISConnection --//Script-wide reference.
local function onToolEquipped(tool)
UISConnection = UIS.InputBegan:Connect(function(input, gameprocessed)
if not gameprocessed then
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if istool then
if not DB then
DB = true
parryre:FireServer()
wait(2)
DB = false
end
end
end
end
end)
end
char.ChildRemoved:Connect(function() --//Change this to Tool.Unequiped, as it's a far better option.
UISConnection:Disconnect()
istool = false
end)
ty for your help but it still doesn’t work for me, (but still thank you tho)
i changed the script to this:
l
ocal UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local block = hum:LoadAnimation(ReplicatedStorage.Assets.Animations.Block)
local mouse = player:GetMouse()
local DB = false
local canParry = false
local parryre = ReplicatedStorage.Assets.Events.Parry
local rs = game:GetService("RunService")
local UISConnection
local function onToolEquipped(tool)
UISConnection = UIS.InputBegan:Connect(function(input, gameprocessed)
if not gameprocessed then
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if canParry then
if not DB then
DB = true
parryre:FireServer()
wait(2)
DB = false
end
end
end
end
end)
end
char.ChildAdded:Connect(function(newChild)
if newChild:IsA("Tool") then
canParry = true
onToolEquipped(newChild)
end
end)
char.ChildRemoved:Connect(function()
UISConnection:Disconnect()
canParry = false
end)
but the error is still there
also i used the child added and child removed instead of tool.--------- because i want it to be used on all tools not just one tool