Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I clone a localscript into every players backpack?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
-- I messed up some of the Syntax in the script mess with it now if u used the incorrect one. MrDefaultMan 113 — 6y
0
Thank you, that worked! JunkellaSyringe 2 — 6y
Ad
Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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()
Log in to vote
0
Answered by 6 years ago

Put the local script into StarterPlayer > StarterPlayerScripts.

Answer this question