How do I pass a bool value through Remote Event? ( Client to Server )

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)

probably FireServer(player,Blocking) im not expert in remote event and dont day anytging if i made a mistake

The player automatically get’s passed as the first argument in a RemoteEvent, so remove “plr” from the FireServer and it should work.

It should look like:

--Client
Remote:FireServer(Blocking)
--Server
Remote.OnServerEvent:Connect(function(plr,blocking)
end)

That didn’t work either. I can give you the game file if it can help you.

{Game}
Block.rbxl (29.7 KB)

Here’s the fixed file Block.rbxl (29.9 KB)

There was another error where you changed the value of Blocking before the if statement ran so it never fired the RemoteEvent

2 Likes

I wanna go ahead and thank you for your effort towards this. I tried out your file and the block will happen but it won’t go away

I don’t understand the problem, it works perfectly fine for me I even put a print statement to print the “Blocking” parameter.

what does “the block won’t go away mean” ?

Edit: There’s no animation if that’s what you are saying is broken, but the RemoteEvent is working fine, you’ll have to add the animation yourself.

Looks like I have to fix the animation. Sorry about the trouble. I didn’t even look at the output to see your print statements go off

1 Like

bro i spent a solid 15 minutes trying to figure out why my code didnt work, thank you :pray::pray::pray: