Script not executing to delete an object after respawning?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Properly delete the prompt for the client after the character respawns

  2. What is the issue? Include screenshots / videos if possible!
    Im having issues with the code im running when the character respawns its supposed to handle the clients proximityPrompt deleting it locally to hide it. Now upon joining there’s no issues its when the character respawns is when the prompt becomes visible for them is the issue This is my server script.
    [2 Player [Rework] - Roblox Studio (gyazo.com)]
    (https://gyazo.com/db5ccebd37808a3d1b1a1bc1b3b6988c)


game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		print("Spawned Setting up " ,char)
		local remote = game.ReplicatedStorage.RemotesFolder.Event
		
		local Prompt = Instance.new("ProximityPrompt")
		Prompt.Parent = char
		Prompt.Name = "PairRequestPrompt"
		Prompt.ObjectText = "Send Pair request"
		Prompt.HoldDuration = 2
		Prompt.MaxActivationDistance = 3
		
		char.Humanoid.JumpHeight = 0
		
		char:SetAttribute("Carried", false)
		char:SetAttribute("Carry", false)
		char:SetAttribute("Throwing", false)
		char:SetAttribute("Thrown", false)
		char:SetAttribute("ChargingJump", false)
		char:SetAttribute("Jumping", false)
		char:SetAttribute("JumpLanded", false)
		char:SetAttribute("ChargingValue", 0)
		
		task.spawn(function()
			local OwnerOfPrompt = game.Players:GetPlayerFromCharacter(Prompt.Parent)
			if Prompt then
				remote:FireClient(plr, plr, Prompt, OwnerOfPrompt, "promptCleanup")
			end
		end)
		
		timeOnJoined[tostring(plr.UserId)] = os.time() -- Storing time they joined in table
		
		task.spawn(function()
			for _, animation in pairs(game.ReplicatedStorage.Animations:GetChildren()) do
				char.Humanoid.Animator:LoadAnimation(animation)
			end
		end)
		
		Prompt.Triggered:Connect(function(PlrWhoTriggered) 
			local OwnerOfPrompt = game.Players:GetPlayerFromCharacter(Prompt.Parent) 
			remote:FireClient(OwnerOfPrompt, PlrWhoTriggered, Prompt, OwnerOfPrompt,"PromptTriggered")
		end)
		local OwnerOfPrompt = game.Players:GetPlayerFromCharacter(Prompt.Parent) 
		remote:FireClient(plr, plr, Prompt, OwnerOfPrompt, "promptCleanup")
	end)
end)


game.Players.PlayerRemoving:Connect(function(plr)
	print(plr.Name .. " Has been in game for " .. os.time() - timeOnJoined[tostring(plr.UserId)] .. " Seconds ") -- here its getting the String and subtracting it from the time they joined
	timeOnJoined[tostring(plr.UserId)] = nil
end)

This is my Client Script

local Event = game.ReplicatedStorage.RemotesFolder.Event
local PairModule = require(game.ReplicatedStorage.Modules.PairModule)
Event.OnClientEvent:Connect(function(plr, prompt, OwnerOfPrompt, action) -- owner of prompt = player, prompt = specific character Prompt
	if action == "promptCleanup" then
		for _, Obj in pairs(plr.Character:GetChildren()) do
			if Obj:IsA("ProximityPrompt") and Obj.Name == "PairRequestPrompt" then
				Obj:Destroy()
				
			end
		end
		print(prompt)
	end
	if action == "PromptTriggered" then 
		task.spawn(function()
			local PairedCharacter = OwnerOfPrompt.Character or OwnerOfPrompt.CharacterAdded:Wait()
			local pairRequestGui = OwnerOfPrompt.PlayerGui.PairRequestGui
			
			pairRequestGui.Enabled = true
			pairRequestGui.PlayerRequestFrame.TextLabel.Text = plr.Name.. " wants to pair with you! "
			
			pairRequestGui.AcceptFrame.ImageButton.Activated:Connect(function()
				pairRequestGui.Enabled = false
				print("Activated")
				PairModule.Pairs(OwnerOfPrompt, plr, "Pair") 
				
			end)
			
			pairRequestGui.DeclineFrame.ImageButton.Activated:Connect(function()
				print("Activated")
				pairRequestGui.Enabled = false

			end)
		end)

	end

end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    ive tried looking none related to my presented issue

This is probably because the characteradded event is firing in the playeradded event, so the script will only run again once a player joins which wouldn’t happen until the player leaves and rejoins. So, what you could do is put your script in startercharacterscripts so it fires everytime the character is added, if you want it to hapen specifically when they respawn you could use debouncing or something.

The local script and server script when moved into starterCharcterScripts doesn’t seem to detect when a character is added

That’s because a playeradded event won’t fire when its in startercharacterscripts, the script is created after the player’s character is added. So delete your characteradded/playeradded event and just write the code without those events.

okay so far it runs when the character respawns, I’m also firing to the server to instance the ProximityPrompt and its not creating it?

Edit: got some quick thought it might be better if i let the server handle that directly

Yeah just make a server script and parent it to startercharacterscripts, serverscripts/localscripts work in startercharacterscripts.