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 put a LocalScript into the LocalPlayer's PlayerGui via Serverside Script?

I have a script that does some certain codes for my ATM Machine, Near the end I am cloning a LocalScript and wanting to put it in the LocalPlayer's PlayerGui, When I put it in the hit.Parent(The character's model) It doesn't work, So I have to do PlayerGui but I've tried a lot of things and none of them worked, Here is the script and the second part is the part that won't work:

local ATMPart = script.Parent
debounce = false
wait ()

ATMPart.Touched:connect(function(hit)
	if debounce == true then return end
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local Torso = hit.Parent.Torso
    local ATM = game.Workspace.ATM
	debounce = true
	
    if player and hit.Parent:FindFirstChild("Card") then
	
	wait ()
	hit.Parent.Humanoid.WalkSpeed = 0
	wait (0.5)
	
	Torso.CFrame = CFrame.new(Torso.Position, ATM.Position)
	
	wait (0.2)
	
    hit.Parent.Humanoid.WalkSpeed = 10	 
	
		
		
		wait (0.1)
		
		local new_script = script:findFirstChild("LocalScript"):Clone()
new_script.Parent = game.StarterPlayer.StarterCharacterScripts



		while wait() do
		local ATM = game.Workspace.ATMLine.Position
	hit.Parent.Humanoid:MoveTo(ATM)
	   wait (4)
	while false do
	
		end
		end
		
	hit.Parent.Humanoid.WalkSpeed = 0
	
	wait (5)
	debounce = false
				
	end
	 end)	
		local new_script = script:findFirstChild("LocalScript"):Clone()
new_script.Parent = game.StarterPlayer.StarterCharacterScripts

There isn't any errors or anything just idk how to put it in the player's gui, I looked at websites and SH.

1 answer

✓ Accepted answer

Why do you try to set your LocalScript's parent to StarterPlayer.StarterCharacterScripts if you want to put it in a player's PlayerGui? This makes no sense; StarterPlayer.StarterCharacterScripts has nothing to do with PlayerGui.

Besides, this doesn't work because the contents of StarterPlayer.StarterCharacterScripts are copied over to every player once, upon spawning. Just like with StarterGui, StarterPack, etc. modifying or adding objects to StarterPlayer.StarterCharacterScripts won't change anything until the player character respawns. But even then, this is no good, because then every other players will get also get a copy upon respawning (Unless network filtering aka 'FilteringEnabled' is enabled, because a client, aka player, cannot force the server into replicating a change to all other clients).

What you want is to get the PlayerGui as a child of the LocalPlayer.

local clone = script:FindFirstChild("LocalScript"):clone()

clone.Parent = player.PlayerGui

Also, if you're copying your LocalScript from some storage location for later use, then please make sure your LocalScript's Disabled property is not checked; That might explain why it doesn't work when parenting it to your player's character model.

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