Localscript not working inside of a client-sided billboard

So, there’s a custom proximity prompt system that I’m making.

There’s a localscript inside of the billboardgui that gets Enabled once the proximity prompt appears, and it should customize the appearance of proximity prompt based on the values of the thing that this proximityprompt is connected to.

The thing is - this script doesn’t seem to be working at all. I tried adding some print commands to the main loop to check when it works and when it doesn’t, but as it seems the script doesn’t work at all.

local HasPower, Tweaking, TextVal
local Text = script.Parent.Text.Textet
local Button = script.Parent.Button
local ButShadow = script.Parent.ButtonShadow

function SaveValues(Part)
	Tweaking = Part:GetAttribute("Tweaking")
	HasPower = Part:GetAttribute("HasPower")
	TextVal = Part:GetAttribute("Text")
end

function randomLetter()
	local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	local randomValue = math.random(1, #alphabet)
	local letter = string.sub(alphabet, randomValue, randomValue)
	return letter
end

-- WHY ISN'T THIS WORKING??? IS THERE SOMETHING MISSING? MUST MORE BLOOD BE SHED???

 -- the constant loop is important to stay because the values of proximityprompt's systems change dynamically. that's the main reason as to why this is inside of a separate script in the first place.
while task.wait() do
	local ParentPart = script.Parent.Parent.Parent
	print(ParentPart:GetAttribute("Active"), ParentPart.Name)
	if ParentPart:GetAttribute("Active") then
		print("fuck yeah")
		SaveValues(ParentPart)
		if Tweaking == true then -- here it should change the looks of the billboardgui
			Button.Text = randomLetter()
			Button.TextColor3 = Color3.fromRGB(144, 81, 81)
			ButShadow.Text = Button.Text
			Text.Text = "ERROR"
		else
			if HasPower == true then
				Button.Text = "E"
				ButShadow.Text = "E"
				Button.TextColor3 = Color3.fromRGB(144, 81, 81)
				Text.Text = TextVal
			else
				Button.Text = "E"
				ButShadow.Text = ""
				Button.TextColor3 = Color3.fromRGB(72, 49, 49)
				Text.Text = TextVal
			end
		end
	end
end

The clone of a billboardGUI gets put inside of the Hitbox part by the main proximity prompt system that i made, then the same system enables this script that is located inside of the billboardGUI through ‘’.Enabled = true’’ command

1 Like

LocalScripts cannot run unless it is a descendant of specific containers, so if the BillboardGui is somewhere in the Workspace (e.g. placed inside of a Part that is not within the Character model), that’s probably why none of the print statements are appearing in the Output.


In order to resolve that, I would recommend placing the BillboardGui into the StarterGui Service, and then set its Adornee property to that “ParentPart” within the Workspace.


The Adornee property basically “attaches” the GUI to the selected part while allowing the GUI to be placed in a different part of the game (which in this case, would be the player’s PlayerGui folder since that is where objects placed in the StarterGui Service are cloned to when a player joins the game).

Because the BillboardGui would now be placed in the PlayerGui container, and the LocalScript is a descendant of the BillboardGui, its code will be able to run in this setup since the LocalScript would now be a descendant of the PlayerGui container (which is one of the places where it can run).




Just in case that was a bit confusing, a simplified explanation is that the code will run because the LocalScript is placed somewhere inside any layer of the PlayerGui folder. In this case, it would be found via the following path:

PlayerPlayerGuiBillboardGuiLocalScript

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.