Problem with firing to Client

Hello,

I’m making a seat lock for my bus. I did almost everything, but the FireClient isn’t working. There are two scripts. The main server script and a serverscript, which RunContext is set to Client. In the main server script everything works, except the FireClient. I’ve put print statments and after the FireClient, in the server script with the different RunContext, it doesn’t print.

Can someone help? Below, I will send the code.

Main server script

local function onSit()
	if db then db=false task.wait(0.033)
		local seat2 = script.Parent.Parent.Parent.Parent.Parent.DriveSeat
		local part = workspace.Part
		
		local seatplayer = seat.Occupant.Parent
		print(seatplayer)

		print("działa do tej pory")
		if seat2:GetPropertyChangedSignal("Occupant") then
			if seat2.Occupant then
				print('smooth')
				local occupant = seat.Occupant
				print('smooth')
				local char = occupant.Parent
				print('smooth')
				local username = char.Name
				print('smooth')
				
				print(username)

				local Player = Players:GetPlayerFromCharacter(seat2.Occupant.Parent)
				print(Player)
				print(Player.Character)
				local PlayerGui = Player:FindFirstChild("PlayerGui")
				print(PlayerGui)
				print('doszło do tego momentu')
				
				print(PlayerGui:FindFirstChild("A-Chassis Interface").AntiJump.Value)
				
				if PlayerGui:FindFirstChild("A-Chassis Interface").AntiJump.Value == true then
					print('przeszło')
					local osoba = seat.Occupant.Parent
					local player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
					
					
					print(seatplayer)
					NewGui.On.Enabled = true
					NewGui.Off.Enabled = false
					print('works')
					
					unbindaction:FireClient(player)
				end	
				if PlayerGui:FindFirstChild("A-Chassis Interface").AntiJump.Value == false then
					local osoba = seat.Occupant.Parent
					local player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)

					print(seatplayer)
					NewGui.On.Enabled = true
					NewGui.Off.Enabled = false
					bindaction:FireClient(player)
				end
			end
		end
		db = true
	end
end

Server script with Client RunContext

local unbindaction = script.Parent.unbindaction
local bindaction = script.Parent.bindaction
local ContextActionService = game:GetService('ContextActionService')

bindaction.OnClientEvent:Connect(function()
	
	print('a')
	wait(0.1)
	ContextActionService:BindAction("jumpAction", Enum.UserInputState, false, Enum.KeyCode.Space)
	print('binded')
end)

unbindaction.OnClientEvent:Connect(function()
	wait(0.1)
	ContextActionService:BindAction("jumpAction")
	print('unbinded')
end)

Aswell I have a second question. Is the ContextActionService done correctly so the user can’t jump out of the seat?

Kind regards

1 Like

Your binding the action again instead of un binding it.

Yea, I have to fix that. Is the binding in the first one good, so the player won’t jump out + a different question. What about the FireClient. Do you have a solution?

it won’t work because your not binding a function to it, specifically this line.

ContextActionService:BindAction("jumpAction", Enum.UserInputState, false, Enum.KeyCode.Space)

Instead you put a Enum.UserInputState, which is not a function, you should try sending back info for the player to jump out. Or make a function that does something similar.

Ok, can you show me how it should look like, because I’m gonna be honest, I’m not a specialist at the ContextActionService?

And that’s why it wasn’t working, because I think something is wrong with firing the event to the Client, because it isn’t printing the client?

I aswell heard that you need to check differently, not in the Output?

You can make another event or use a remote function instead, I would recommend to use remote functions, but lets just use a second remote event as to not change things up too much.

local unbindaction = script.Parent.unbindaction
local bindaction = script.Parent.bindaction
local fireToServerEvent = --Remote Location
local ContextActionService = game:GetService('ContextActionService')

bindaction.OnClientEvent:Connect(function()
	local function FireBackJumpAction(a,b,c)
if b == Enum.UserInputState.Begin then
fireToServer:FireServer()
end
      end
	print('a')
	wait(0.1)
	ContextActionService:BindAction("jumpAction", FireBackJumpAction, false, Enum.KeyCode.Space)
	print('binded')
end)

unbindaction.OnClientEvent:Connect(function()
	wait(0.1)
	ContextActionService:UnbindAction("jumpAction")
	print('unbinded')
end)

Then add a listener to the main script, and make the player jump out the seat there, im not really experienced with A-chassis, but I think you can do it, if you need any help, im right here.

1 Like

I think there is no point to send again the RemoteEvent back to the server, because I have a script for the unbind, but I will test both. I will tell you if it works tomorrow. Thanks for your help :slight_smile:

1 Like

Bro, I tested the solution and it works tysm

1 Like