I have a blocking script and I just want it so you dont take damage while blocking. If anyone knows how to fix this please help!
Local Script:
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local blockingAnim = script:WaitForChild("BlockingAnim")
local CD = 1
local debounce = false
local BlockingRemote = game.ReplicatedStorage.BlockRemote.Blocking
local RemoveBlocking = game.ReplicatedStorage.BlockRemote.RemoveBlocking
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local gaurdingAnimation = hum:LoadAnimation(blockingAnim)
uis.InputBegan:Connect(function(input,Typing)
if not Typing then
if input.KeyCode == Enum.KeyCode.F and debounce == false then
if char:FindFirstChild("BlockBreak") == nil and char:FindFirstChild("Stun") == nil and char:FindFirstChild("eStun") == nil then
debounce = true
BlockingRemote:FireServer()
game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 65}):Play()
hum.WalkSpeed = 7
gaurdingAnimation:Play()
wait(CD)
debounce = false
end
end
end
end)
uis.InputEnded:Connect(function(input,Typing)
if input.KeyCode == Enum.KeyCode.F then
RemoveBlocking:FireServer()
game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 70}):Play()
gaurdingAnimation:Stop()
hum.WalkSpeed = 15
end
end)
RemoveBlocking.OnClientEvent:Connect(function()
RemoveBlocking:FireServer()
game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 70}):Play()
gaurdingAnimation:Stop()
hum.WalkSpeed = 15
end)
Script:
local Block = game.ReplicatedStorage.BlockRemote.Blocking
local Remove = game.ReplicatedStorage.BlockRemote.RemoveBlocking
Block.OnServerEvent:Connect(function(plr)
local char = plr.Character
local BlockingValue = Instance.new("BoolValue",char)
BlockingValue.Name = "IsBlocking"
end)
Remove.OnServerEvent:Connect(function(plr)
for i,v in pairs(plr.Character:GetChildren())do
if v.Name == "IsBlocking" then
v:Destroy()
end
end
end)
Do you know how to do something like this? I attempted but instead of preventing damage it just heals the character to max health which i dont want.
Local:
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local blockingAnim = script:WaitForChild("BlockingAnim")
local CD = 1
local debounce = false
local BlockingRemote = game.ReplicatedStorage.BlockRemote.Blocking
local RemoveBlocking = game.ReplicatedStorage.BlockRemote.RemoveBlocking
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local gaurdingAnimation = hum:LoadAnimation(blockingAnim)
hum.HealthChanged:Connect(function(newHealth)
local isBlocking = char:FindFirstChild("IsBlocking")
if isBlocking then
hum.Health = newHealth + (hum.MaxHealth - newHealth)
end
end)
uis.InputBegan:Connect(function(input,Typing)
if not Typing then
if input.KeyCode == Enum.KeyCode.F and debounce == false then
if char:FindFirstChild("BlockBreak") == nil and char:FindFirstChild("Stun") == nil and char:FindFirstChild("eStun") == nil then
debounce = true
BlockingRemote:FireServer()
game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 65}):Play()
hum.WalkSpeed = 7
gaurdingAnimation:Play()
wait(CD)
debounce = false
end
end
end
end)
uis.InputEnded:Connect(function(input,Typing)
if input.KeyCode == Enum.KeyCode.F then
RemoveBlocking:FireServer()
game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 70}):Play()
gaurdingAnimation:Stop()
hum.WalkSpeed = 15
end
end)
RemoveBlocking.OnClientEvent:Connect(function()
RemoveBlocking:FireServer()
game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 70}):Play()
gaurdingAnimation:Stop()
hum.WalkSpeed = 15
end)
It seems like you’re dealing damage from the server. Why not check if they are blocking from there before dealing the damage? It would be quite unsafe to let the client control their health.