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

How can I edit my localscript so it works in a regular script?

So I created a (local)script that places a billboard GUI above your head with some text on it. The problem is, you can only see your billboard GUI and no one else's due to it being placed in a localscript.

I'm pretty sure everything in the script is regular script compatible, but this one line of code is blocking me from placing it in a regular script and I do not know of an alternative for it:

player = game.Players.LocalPlayer

If you'd like to see the script in its entirety:

player = game.Players.LocalPlayer
character = player.Character

script.Parent.FocusLost:connect(function()
		local bg = Instance.new("BillboardGui")
			bg.Parent = character.Head
			bg.Size = UDim2.new(1, 0, 1, 0)
			bg.StudsOffset = Vector3.new(0, 2, 0)
		local frame = Instance.new("Frame")
			frame.Parent = bg
			frame.Size = UDim2.new(1, 0, 1, 0)
			frame.BackgroundTransparency = 1
		local text = Instance.new("TextLabel")
			text.Parent = frame
			text.Position = UDim2.new(0.25, 0, 0.25, 0)
			text.Size = UDim2.new(0.5, 0, 0.5, 0)
			text.Text = script.Parent.Text
			text.BackgroundTransparency = 1
			text.TextColor3 = Color3.new(1, 1, 1)
			text.Font = "ArialBold"
			text.FontSize = "Size24"			
end)

tl;dr: What is a regular script compatible alternative version to LocalPlayer?

1 answer

✓ Accepted answer

The simplest solution is to put the Script inside the Player (PlayerGui or Backpack) (or their character), and then just reference up to the appropriate Parent.


If we had an object hierarchy like this:

Players
	Player
		PlayerGui
			Frame
				TextBox
					Script

Then we would use something like this to refer to that Player

local box = script.Parent;
local frame = box.Parent;
local gui = frame.Parent;
local player = gui.Parent;

Or, in just one line:

local player = script.Parent.Parent.Parent.Parent;

Note that that hierarchy I showed would be analagous to

StarterGui
	Frame
		TextBox
			Script

Since the contents of StarterGui get copied into each PlayerGui.

7 comments

0

Hi BlueTaslem, thank you for responding quickly. I don't really understand what you mean by putting the script in the Player. Could you try to explain a little more and a few more examples? Thank you :)

0

Edited to be more specific!

0

Hey BlueTaslem, thanks alot for editing your answer - it worked perfectly! Problem is, only in solo mode. I think someone showed me a quick fix for this problem, but I can't seem to remember, or maybe I'm just dreaming about it haha. Do you have a suggestion to fix this problem?

0

Check again, and check the output online (F9)

0

I couldn't find the fix someone told me. D:! I checked the online output, and nothing showed except for roblox links highlighted in red with the sentence "The parameter is incorrect." Also, can we use the ROBLOX PM system to contact each other? I think it'd be easier .

0

Sure, you can PM me about finer details

0

Okay, message sent! :D

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