When buttonclick it clone part to Every player's location

Hello I want to ask for help according to the title above does anyone know how it works and how I make a script yes I am, make but it doesn’t work, can anyone help give me an example script? Oh yes btw I’m using remoteevent
Thx.

Well you can use the remote event to RemoteEvent:FireAllClients(arg)

1 Like

From the local script you fire a remote to server, a server script receive the remote call and the server script should iterate all players and clone a part on each location

1 Like

when i use local script i sayas error fireallclient can only be called by server, while im clicking the button to firing the event

I already explained, you should do the FireAllClient from a server script, cant be used from a local script. But you dont even need to use that.

From a Local Script you use FireServer(). Then in a server script you use Remote.OnServerEvent(player), the server script now should do a for loop on all players in server clone the part and place it on each player coordinates

1 Like

Be sure to format your code so its readable for users of forum. Cntrl+E or the button.

You forgot to iterate all players in server, you are doing it only for the player who fired the remote

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local remoteEvent = ReplicatedStorage.AamTum_EVENT:WaitForChild(“Sphere_2”)
local model = ReplicatedStorage.AamTum_EVENT.OBJ:WaitForChild(“Sphere_2”) – replace “YourModel” with the name of your model in ReplicatedStorage

remoteEvent.OnServerEvent:Connect(function(player)
	warn(player, "asked to clone parts")
	for _, aPlr in pairs(game.Players:GetPlayers()) do
		if aPlr.Character then
			local clone = model:Clone() -- clone the model
			--
			local Sound = script.Sound:Clone()
			Sound.Parent = workspace.Terrain
			Sound:Play()
			--
			clone.Parent = workspace.Terrain -- parent the clone to the workspace
			local modelSize = clone:GetExtentsSize() -- get the size of the model
			clone:SetPrimaryPartCFrame(aPlr.Character.Head.CFrame * CFrame.new(0, modelSize.Y/2 + aPlr.Character.Head.Size.Y/2, 0)) -- position the clone above the player's head
			task.wait(7)
			-- wait for 9 seconds
			Sound:Destroy()
			clone:Destroy() -- destroy the clone
		end
	end
end)
2 Likes

ok it works tysm maam for the help :scream: btw it has some dlay for each player maybe network issue

1 Like

No problem. Dont forget to mark the solution.

What do you mean? do you want to include a delay on each iteration of the loop?

1 Like

i mean that the event didnt fire at the same time, it like the remote event take turn after the next players remote been fire

Yes, but that’s what you added since your original script. Its because this line:
task.wait(7)

On each iteration of the for loop, it “grabs” one player, clones a model, place it, create a sound, then it waits 7 seconds. Then it destroy the model, then it start with the next player, each iteration waits 7 seconds to continue with the next player.

If you dont want that wait of 7 seconds to happen between players, but you still want to Destroy() the sound and the clone after the 7 seconds. You could use task.delay() or Debris:

local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local remoteEvent = ReplicatedStorage.AamTum_EVENT:WaitForChild(“Sphere_2”)
local model = ReplicatedStorage.AamTum_EVENT.OBJ:WaitForChild(“Sphere_2”) – replace “YourModel” with the name of your model in ReplicatedStorage

remoteEvent.OnServerEvent:Connect(function(player)
	warn(player, "asked to clone parts")
	for _, aPlr in pairs(game.Players:GetPlayers()) do
		if aPlr.Character then
			local clone = model:Clone() -- clone the model
			--
			local Sound = script.Sound:Clone()
			Sound.Parent = workspace.Terrain
			Sound:Play()
			--
			clone.Parent = workspace.Terrain -- parent the clone to the workspace
			local modelSize = clone:GetExtentsSize() -- get the size of the model
			clone:SetPrimaryPartCFrame(aPlr.Character.Head.CFrame * CFrame.new(0, modelSize.Y/2 + aPlr.Character.Head.Size.Y/2, 0)) -- position the clone above the player's head
			
			Debris:AddItem(Sound, 7) -- destroy sound after 7 seconds
			Debris:AddItem(clone, 7) -- destroy clone after 7 sec
			
			-- OR
			--task.delay(7, function()
			--	Sound:Destroy()
			--	clone:Destroy()
			--end)
		end
	end
end)

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