Deleting Client Based Effects Properly?

https://streamable.com/u5bps6

So I’m having this issue where if a player dies while effects are out they freeze and don’t delete. Even if I use debris service and whatnot. Since I’m firing the effects to every player using fireallclients I tried doing the same when on death with humanoid.died function then fireserver to then fireallclients to get the playerdebris folder my script creates and clear it for every player in game but the information always came back nil as if the folder was never there to begin with. is there an easier or better solution then what im doing?

Humanoid.Died:Connect(function()
	local plrdebris = workspace:FindFirstChild("PlayerDebris")
	local plrfolder = plrdebris:FindFirstChild(Player.Name)
	
	Destroy:FireServer(plrfolder)
end)


Destroy.OnClientEvent:Connect(function(plrfolder)
	for i,v in pairs(plrfolder:GetChildren()) do
		if v then
			v:Destroy()
		end
		print("Success!")
	end
end)

--server side
destroy.OnServerEvent:Connect(function(PlrName)
	destroy:FireAllClients(PlrName)

end)

--how the folder is created from executing the move and recieving the info back on client side
Remote.OnClientEvent:Connect(function(Type,Models,Character,HumRT)
	local PlayerDebris = workspace:FindFirstChild("PlayerDebris")
	local PlrFolder = PlayerDebris:FindFirstChild(Player.Name) or Instance.new("Folder")
	PlrFolder.Name = Player.Name
	PlrFolder.Parent = PlayerDebris
	
	if Type == "Grow" then
		Grow(Models,PlrFolder,Character,HumRT)
	elseif Type == "Shrink" then
		Shrink(Models,PlrFolder,Character,HumRT)
	end
end)


Ok so firstly…

When the player dies, the client fires the server with an Instance that is created on the client. Which would be inaccessible to the server. So you should send the Name instead. Secondly, on the ServerEvent. There are 2 parameters, the (player/client, TheFolder). You have only 1 parameter as the “plrfolder” which is in reality the Player/Client that fired the Remote.

So on the ClientEvent, you are essentially iterating through the Client that fired the Event initiallty. And since the server can’t access the Client made folder, and you’ll have to send the name, now the Client Event must change as well. So that it finds the Client Folder on it’s own end then iterate and destroy.

2 Likes

thankyou! I also had to do few extra things to get it to work but you were also right.

1 Like