:FireClient() does not work?

I am trying to create a script that gives the player a certain amount of WalkSpeed depending on an IntValue when the character respawns. This feature works, but when I try and use a RemoteEvent to send it back to the LocalScript to update the player’s gui it stops working. No errors appear in the output.

Server Script

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		if plr:FindFirstChild("Values") then
			local hum = character:FindFirstChild("Humanoid")
			hum.WalkSpeed = plr.Values.WalkSpeed.Value
			rs:WaitForChild("UpdateGui"):FireClient(plr)
		end
	end)
end)

Local Script

local rs = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local gui = plr.PlayerGui:WaitForChild("ValueGui")
local textLabel = gui.SpeedBackground.SpeedValue

local function updateGui()
	print("test")
	if hum.WalkSpeed == 120 then
		textLabel.Text = "Speed: "..hum.WalkSpeed.." (MAX)"
	else
		textLabel.Text = "Speed: "..hum.WalkSpeed
	end
end

rs:WaitForChild("UpdateGui").OnClientEvent:Connect(updateGui)

The script never enters the function so I’m assuming that something is wrong within the RemoteEvent.

You can edit posts instead of making duplicates

Why did you repost the same question?
https://devforum.roblox.com/t/fireclient-does-not-work/1897527/4

I am aware of that, I just realized it, the website is bugging out for some reason

Im not sure why it is not working. Maybe try changing the Instance “char” to character and remove the :waitforchild() function for the remote event, cuz its already there.
Oh also check for errors in the output :slight_smile:
Change the local script to this:

local rs = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local gui = plr.PlayerGui:WaitForChild("ValueGui")
local textLabel = gui.SpeedBackground.SpeedValue

local function updateGui()
	if hum.WalkSpeed == 120 then
		textLabel.Text = "Speed: "..hum.WalkSpeed.." (MAX)"
	else
		textLabel.Text = "Speed: "..hum.WalkSpeed
	end
end

rs.UpdateGui.OnClientEvent:Connect(updateGui)

Server Script:

game.Players.PlayerAdded:Connect(function(plr)
if player then
	plr.CharacterAdded:Connect(function(character)
		if plr:FindFirstChild("Values") then
			local hum = character:FindFirstChild("Humanoid")
			hum.WalkSpeed = plr.Values.WalkSpeed.Value
			rs:WaitForChild("UpdateGui"):FireClient(plr)
		end
end)
	end
end)

I think this would be the only reason your script doesn’t run. The RemoteEvent seems good.

Instead of local char = plr.CharacterAdded:Wait() do local char = plr.Character or plr.CharacterAdded:Wait()

I don’t know if this would help, but it’s worth trying.

2 Likes

Probably because the character load before connecting, that’s why it’s not firing you can test that if it does fire when restarting your character.

Your scripts do little to nothing to check if the character (or player) already exists. This may be the root cause of your issue.

You could try this:
ServerScript:

local function added(plr)
	local function handle(character)
		if plr:FindFirstChild("Values") then
			local hum = character:WaitForChild("Humanoid")
			hum.WalkSpeed = plr.Values.WalkSpeed.Value
			rs:WaitForChild("UpdateGui"):FireClient(plr)
		end
	end
	local character = plr.Character
	plr.CharacterAdded:Connect(handle)
	if character then
		task.spawn(handle, character)
	end
end
game.Players.PlayerAdded:Connect(added)
for _, plr in game.Players:GetPlayers() do
	task.spawn(added, plr)
end

LocalScript:

local rs = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local gui = plr.PlayerGui:WaitForChild("ValueGui")
local textLabel = gui.SpeedBackground.SpeedValue

local function updateGui()
	print("test")
	if hum.WalkSpeed == 120 then
		textLabel.Text = "Speed: "..hum.WalkSpeed.." (MAX)"
	else
		textLabel.Text = "Speed: "..hum.WalkSpeed
	end
end

rs:WaitForChild("UpdateGui").OnClientEvent:Connect(updateGui)