Cloning a local script to a player's UI

Hi,

I am currently making a system that will help developers not get the products stolen. Without going into too much detail, I have made a script that sends a message via webhook to discord. Then inside that script, there is a localscript that contains the UI message using instance.new() and all that.

How would I make it so that you could move the local script to the player’s UI?
image

The main script called, “LeakProtection” is in workspace and the “leak” local script is a child of it.

I’ve already tried putting this in the local script but it didn’t work:

local gui = script 

	for i, v in pairs(game.Players:GetChildren()) do -- loops through all players in the server
	local clone = gui:Clone()
	clone.Parent = v.PlayerGui
end

I’m pretty sure you can’t clone on a local script.

A local script can’t run in the workspace or in any descendants of an object in the workspace.

As for

Where in the world did you get that from???

So where would a local script that is inside a script be able to run?

Not many places. It would be easier to just parent the LocalScript to something like StarterPlayerScripts, then if you need to reference the LocalScript just do player.PlayerScripts.leak

The school for noobs. Where did you find the correct way???

So I just tried it and it works, though the point is to make a leak protection system simple so a developer can just insert it into their model and the script does all the work. Would that even be possible because the local script makes the GUI?

What do you mean, you can clone from local scripts. There is no correct way, you clone from a local script the same way you would a normal script. The reason his script won’t work is because:

What if I were to put the local script in the script under Workspace, and then have the script clone the localscript to StarterPlayerScripts and then have the local script run? Would that work?

@domboss37 Would this work? I don’t need the local script to run while in workspace (obviously), I just need it to run in SPS.

This actually should work just note that you would need to clone it into the players PlayerScripts and not StarterPlayerScripts

1 Like

A single client’s local scripts cannot access the PlayerGui containers of other clients.

image

1 Like
local plr = Players.LocalPlayer
local clone = script.leak:Clone()
clone = plr.PlayerScripts

So this is what I put in the script and it is not working. Any help?

Well

Is a ServerScript (correct me if I’m wrong in that) but anyways, you can’t get “LocalPlayer” in server scripts, for your use case do this:

local Players = game:GetService("Players")

local function OnPlayerAdded(player)
    local clone = script.leak:Clone()
    clone = player.PlayerScripts
end 

Players.PlayerAdded:Connect(OnPlayerAdded)

It still doesn’t work.
image

Shoot, I just realized I forgot .Parent after

But either way
use WaitForChild as the PlayerScripts might not be loaded yet


local Players = game:GetService("Players")

local function OnPlayerAdded(player)
    local clone = script.leak:Clone()
    clone.Parent = player:WaitForChild("PlayerScripts")
end 

Players.PlayerAdded:Connect(OnPlayerAdded)


Still not working

Okay, try putting it in PlayerGui, like this:

local Players = game:GetService("Players")

local function OnPlayerAdded(player)
    local clone = script.leak:Clone()
    clone.Parent = player:WaitForChild("PlayerGui")
end 

Players.PlayerAdded:Connect(OnPlayerAdded)
1 Like