Client not Receiving Remote Event after Respawn

I have a remote event that fires after a Player.CharacterAdded event to the client, which works for the first time spawning in, but not after respawning.
The issue seems to be on the client side, as a print statement within the OnClientEvent only sends the first time. There are no errors in the output either, so I believe I am just making a simple mistake.
I spent a while trying to fix it myself, but couldn’t quite figure it out or find any topics on this issue.

--Function that fires the event
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local prompt = Instance.new("ProximityPrompt"):Clone()
		local root = character:WaitForChild("HumanoidRootPart")

		prompt.Parent = root
		prompt.Name = "PairPrompt"
		prompt.ObjectText = player.DisplayName
		prompt.ActionText = "Pair"
		prompt.RequiresLineOfSight = false
		
		RemoveEvent:FireClient(player)
		print("Fired")
	end)
end)
1 Like

Where do you put your client code, and what is your client code?

1 Like

Client code is in StarterCharacterScripts

local RemoveEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemovePromptEvent")

RemoveEvent.OnClientEvent:Connect(function()
	print("Received")
	local plr = game.Players.LocalPlayer
	local chr = plr.Character
	local root = chr:WaitForChild("HumanoidRootPart")
	
	root:FindFirstChild("PairPrompt"):Destroy()
end)

I moved the variables out of the function as it seemed to be unnecessary.

local RemoveEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemovePromptEvent")

local plr = game.Players.LocalPlayer
local chr = plr.Character
local root = chr:WaitForChild("HumanoidRootPart")

RemoveEvent.OnClientEvent:Connect(function()
	print("Received")
	root:FindFirstChild("PairPrompt"):Destroy()
end)

Why are you using a RemoteEvent instead of just using :Destroy on the client?

Code:

local plr = game.Players.LocalPlayer
local chr = plr.Character
local root = chr:WaitForChild("HumanoidRootPart")
root:WaitForChild("PairPrompt"):Destroy()

Forgot it runs on respawn automatically, I was overthinking. Thanks.

1 Like

Also, unrelated, but you should be setting .Parent last.

So ideally, your server code should be this:

--Function that fires the event
local Players = game:GetService("Players")

Players .PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local root = character:WaitForChild("HumanoidRootPart")

		local prompt = Instance.new("ProximityPrompt"):Clone()
		prompt.Name = "PairPrompt"
		prompt.ObjectText = player.DisplayName
		prompt.ActionText = "Pair"
		prompt.RequiresLineOfSight = false
		prompt.Parent = root
	end)
end)
1 Like

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