How can I fix this? I’m trying to get the player to hold down B to block and stop blocking when they let go of B. How would I get the server to detect that with a bool value going through a remote event?
{Client}
local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local Blocking = false
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("PlayerAction").Block
local Players = game:GetService("Players")
local Plr = Players.LocalPlayer
local Mouse = Plr:GetMouse()
UIS.InputBegan:Connect(function(Input, GP)
if GP then return end
local plr = game.Players.LocalPlayer
Blocking = true
if Input.KeyCode == Enum.KeyCode.B and not Blocking then
Remote:FireServer(plr)-- Fires Server
end
end)
UIS.InputEnded:Connect(function(Input, GP)
if GP then return end
local plr = game.Players.LocalPlayer
Blocking = false
if Input.KeyCode == Enum.KeyCode.B and Blocking then
Remote:FireServer(plr,Blocking) -- Fires Server
end
end)
{Server}
local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local Blocking = false
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("PlayerAction").Block
local Players = game:GetService("Players")
local Plr = Players.LocalPlayer
Remote.OnServerEvent:Connect(function(plr,Blocking)
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Animation = RS:WaitForChild("PlayerAction").Block.BlockAni
local BlockAnimation = humanoid:LoadAnimation(Animation)
if Blocking == true then
BlockAnimation:Play()
end
if Blocking == false then
BlockAnimation:Stop()
end
end)