Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I clone a localscript into every players backpack?

I wasn't too sure where to start so all I've tried is this.

function onClick(ply)
	local c=game.Players:children()
	for i=1, #c do
		game.Soundscape.CutsceneLocalScript:Clone().Parent = c[i].Backpack
	end
end

script.Parent.MouseButton1Click:connnect(onClick)

How do I make this work? Or is there another, easier way to make the local script play for everyone at once?

3 answers

✓ Accepted answer

I would do what hiim said, but to do exactly what you asked use ipairs.

Example:

script.Parent.MouseButton1Click:connect(function()
	for i,v in ipairs(game.Players:GetChildren()) do
		if v:FindFirstChild('Backpack') then
			clone = (ur localscript):Clone()
			clone.Parent = v.Backpack
		end
	end
end)

Ipairs

2 comments

0

-- I messed up some of the Syntax in the script mess with it now if u used the incorrect one.

0

Thank you, that worked!

You can use a server to client RemoteEvent and the FireAllClients method. Put a LocalScript in StarterPlayer > StarterCharacterScripts. Put a Script in ServerScriptService.

In your LocalScript put this in to test.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("same_time")

RemoteEvent.OnClientEvent:connect(function()
	print("Cutscene fired for ", game.Players.LocalPlayer)
end)

In your script put this in to test

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Remote_event = Instance.new("RemoteEvent")
Remote_event.Name = 'same_time'
Remote_event.Parent = ReplicatedStorage;


-- Make sure there's a player to recieve it, this is just for testing purposes, comment out later.
game:GetService('Players').PlayerAdded:wait()

Remote_event:FireAllClients()

Put the local script into StarterPlayer > StarterPlayerScripts.

This discussion is preserved as it was. New answers, comments, and votes are closed.