An object unintentionally duplicates for all players when it's meant to be for one player

This is a code that should replicate itself from ServerStorage under player ‘s HRP once that player has activated the RemoteEvent (basically clicked a button that fires the event), but instead it duplicates under all in-server players’ HRPs. Looking for a way to turn it into one-player event. Will appreciate any help.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		game.ReplicatedStorage:FindFirstChild("AURA"):FindFirstChild("A1").OnServerEvent:Connect(function()
			local Torso = game.Workspace:FindFirstChild(player.Name):FindFirstChild("HumanoidRootPart")
			local ef = game.ServerStorage:FindFirstChild("AURAS"):FindFirstChild("CT"):Clone()
			ef.Parent = Torso
		end)
	end)
end)

I have now realized this is likely related to RemoveEvent as the event is fired for all players, kinda just like how it’s supposed to work in such script. Been trying to change it, DevForum doesn’t help and Create Hub just kinda exists (doesn’t even prompt errors for me now). Any way in helping will be awesum.

I believe this is what you are trying to accomplish. In the code you have provided, the remote event callback function will replicate the “ef” under every character’s Torso because you put the callback inside every player’s character loaded event.

Instead, you should place the remote event callback by itself. Inside it, you should use the “plr” parameter passed to it by default which would refer to the player whose client have called/fired the remote. Then you can do whatever you want to that individual player.

game.ReplicatedStorage:FindFirstChild("AURA"):FindFirstChild("A1").OnServerEvent:Connect(function(plr)
    if plr.Character then
		local Torso = plr.Character:FindFirstChild("HumanoidRootPart")
		local ef = game.ServerStorage:FindFirstChild("AURAS"):FindFirstChild("CT"):Clone()
		ef.Parent = Torso
    end
end)
1 Like

okay, nevermind, the PlayerAdded & CharacterAdded were the problem of the code, I thought you gave me just a portion of my code lol

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