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)
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()