FireClient() not executing

Hello! First time posting here, so I made a simple backpack system that stores the item in a folder in ServerStorage, and I noticed that when I stored a item with a gui, it couldnt disable it so of course I used a remote event from client to server to try and fix that but for some reason while giving no errors, the condition is being met but only FireClient() is not getting executed, like its skipping it or something.

Heres the code:

Server sided script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Storage = game:GetService("ServerStorage")

local inventoryStore = ReplicatedStorage.RemoteEvents.InventoryStore
local flashlightDisabled = ReplicatedStorage.RemoteEvents.FlashlightDisable

local playerItemsFolder = Instance.new("Folder")
playerItemsFolder.Name = "PlayerItems"
playerItemsFolder.Parent = Storage

inventoryStore.OnServerEvent:Connect(function(player, action, toolName)
	if action == "StoreTool" then
		toolName.Parent = playerItemsFolder
		if toolName.Name == "FlashLight" then
			flashlightDisabled:FireClient(player)
			print("Flashlight found!")
		end
	elseif action == "RetrieveTool" then
		local storedTool = playerItemsFolder:FindFirstChild(toolName)
		if storedTool then
			storedTool.Parent = player.Backpack
			flashlightDisabled:FireClient(player,action)
		end
	end
end)

Client sided script:

-- Main Services
local TweenService = game:GetService("TweenService")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Misc
local PlayerGUI = Players.LocalPlayer:WaitForChild("PlayerGui")
local batteryBar = PlayerGUI.Battery.Frame.BatteryBar
local camera = workspace.CurrentCamera
local battery = workspace.Batteries

-- Remote Events
local FlashOn = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("FlashLightOn")
local flashOff = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("FlashLightOff")
local batteryDestroy = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("BatteryDestroy")
local flashlightDisable = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("FlashlightDisable")

-- Tween Info
local info = TweenInfo.new(
	30,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)
local info2 = TweenInfo.new(
	0.3,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local batteryBarSize = batteryBar.Size 
local uiTweenDown = TweenService:Create(batteryBar, info, {Size = UDim2.new(0, 64, 0, 0)})
local uiTweenUP = TweenService:Create(batteryBar, info2, {Size = UDim2.new(0, 64, 0, -214)})
local turnOnAndOff = "TurnOnOff"

local Clicks2 = 0

local function TurnOnAndOff(actionName, inputObject)
	if actionName == turnOnAndOff and inputObject == Enum.UserInputState.Begin then
		Clicks2 += 1
		if Clicks2 == 1 then
			script.Parent.Handle.Sound:Play()
			FlashOn:FireServer()
			uiTweenDown:Play()
		elseif Clicks2 >= 2 then
			flashOff:FireServer()
			uiTweenDown:Pause()
			Clicks2 = 0
		end
	end
end

for _, battery in ipairs(battery:GetChildren()) do
	local prompt = Instance.new("ProximityPrompt")
	prompt.Parent = battery
	prompt.Triggered:Connect(function()
		if batteryBar.Size ~= batteryBarSize then
			batteryDestroy:FireServer(battery)
			uiTweenUP:Play()
			uiTweenUP.Completed:Connect(function()
				uiTweenUP:Pause()
				ContextActionService:BindAction(turnOnAndOff, TurnOnAndOff, true, Enum.KeyCode.F)
				print("Battery recharged!")
			end)
		end
	end)
end

local bodyParts = {
	"RightShoulder",
	"Neck"
}

local connection
local root = Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")

script.Parent.Equipped:Connect(function()
	script.Parent.Handle.equip:Play()
	ContextActionService:BindAction(turnOnAndOff, TurnOnAndOff, true, Enum.KeyCode.F)
	PlayerGUI.Battery.Enabled = true
	connection = RunService.Heartbeat:Connect(function()
		local cameraDirection = root.CFrame:ToObjectSpace(camera.CFrame).LookVector
		for _, bodyPart in ipairs(bodyParts) do
			local bodyPartArms = Players.LocalPlayer.Character:FindFirstChild(bodyPart, true)
			if bodyPartArms then
				bodyPartArms.C0 = CFrame.new(bodyPartArms.C0.X, bodyPartArms.C0.Y, 0) * CFrame.Angles(0, -math.asin(cameraDirection.X), 0) * CFrame.Angles(math.asin(cameraDirection.Y), 0, 0)
			end
		end
	end)
end)

local function UnequipTool()
	PlayerGUI.Battery.Enabled = false
	ContextActionService:UnbindAction(turnOnAndOff)
	if connection then
		connection:Disconnect()
	end
	for _, bodyPart in ipairs(bodyParts) do
		local bodyPartArms2 = Players.LocalPlayer.Character:FindFirstChild(bodyPart, true)
		if bodyPartArms2 then
			bodyPartArms2.C0 = CFrame.new(bodyPartArms2.C0.X, bodyPartArms2.C0.Y, 0)
		end
	end
end

script.Parent.Unequipped:Connect(function()
	UnequipTool()
end)

flashlightDisable.OnClientEvent:Connect(function(action)
	UnequipTool()
	print("RemoteEvent fired.")
end)

uiTweenDown.Completed:Connect(function()
	flashOff:FireServer()
	ContextActionService:UnbindAction(turnOnAndOff)
end)
1 Like

Btw one thing to notice is that in the elseif condition i also added another FireClient() for testing purposes just to confirm its only in the conditionals that is doing that, when i use FireClient() outside of the conditionals it works fine so the remote event is correctly set up, the problem lies when FireClient() is inside of the conditionals.

The problem became extremely complex, so I rewrote this part of the script and now the problem is solved. So post is closing here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.