Why does this not work?

Hello again!
It is my second post today and I am now here to ask, why does my code not work?
It is a script to make a billboard gui textlabel text change, but it doesn’t work.

Ths is my code:

Let me explain what I did here:

  • I first wanted to make a shortcut to get the name of the player.
  • Then, I did the Mousebutton1Click function
  • Then i set the text I wanted and the stroke color

But somehow it does not seem to work, what is wrong in my code?

2 Likes

What is the error can you post a picture of it

1 Like

image

1 Like

Do game.Workspace[judagor].therest

1 Like

one problem I see is you’re trying to access the head of the player through his name[string],

try this:

local Players = game:GetService("Players")
local Jug = Players.LocalPlayer

local Char = Jug.Character or Jug.CharacterAdded:Wait()
1 Like

???

I am trying to access his head someway

Try this -

local Players = game:GetService("Players")
local Jug = Players.LocalPlayer

local Char = Jug.Character or Jug.CharacterAdded:Wait()

Make some adjustments, and acccess the head through Char

Do i have to add the or Jug.CharacterAdded:Wait() too?

Optional, because that would make sure even when the character isnt loaded yet, it’d wait.

local Players = game:GetService("Players")
local Jug = Players.LocalPlayer

local Char = Jug.Character or Jug.CharacterAdded:Wait()
local Head = Char:FindFirstChild("Head")
local Tag = Head:WaitForChild("BillboardGui")

script.Parent.MouseButton1Click:Connect(function()
    Tag.TextLabel.Text = "Your Text"
    Tag.TextLabel.TextStrokeColor3 = Color3.fromRGB(255,0,0)
end)

[I suggest avoid naming instances with classes’ names]

Bro the rest i dont wanna type the whole thing out for u.
Replace game.workspace.jasugar with what i sent leave

How is the player going to click a part if he hasnt spawned lmao. You are just complicating it. You arent wrong to have the check but that isnt the problem with his code

Not the best way to do this, but ressembles your own solution the most. Try this:

local name = game.Players.LocalPlayer.Name

script.Parent.MouseButton1Click:Connect(function()
  game.Workspace:FindFirstChild(name).Head.BillboardGui.Textlabel.Text = "*building* | Hospital worker"
  game.Workspace:FindFirstChild(name).Head.BillboardGui.Textlabel.TextStrokeColor3 = Color3.new(1, 0, 0)
end)
1 Like

localplayer.Name returnes as string so when he does game.workspace.jadugar the sceipt breaks

local Players = game:GetService("Players")
local Jug = Players.LocalPlayer

local Char = Jug.Character or Jug.CharacterAdded:Wait()
local Head = Char:FindFirstChild("Head")
local Tag = Head:WaitForChild("BillboardGui")

script.Parent.MouseButton1Click:Connect(function()
    Tag.TextLabel.Text = "Your Text"
    Tag.TextLabel.TextStrokeColor3 = Color3.fromRGB(255,0,0)
end)

Here, try this.
As I’ve suggested above already.

One of the issues I saw, was that you tried to assign TextStrokeColor3 as a string value, instead of a Color3 value.

Gives me this in the output:
image
(name blured bc it is the username of somebody in my devgroup)

Change the head variable from find first child to wait for child

TL;DR: please stop trolling and listen to everyone’s answers. Sometimes they will make random things like text = ..., which means that its a replacement. next time, copy and paste your script instead of making an image of it, as it will save time and your disk space. all the time you were copying and pasting script answers without making necessary adjustments, which consumed an unnecessary amount of time for people who are trying to help you solve your issue. A reminder is that common sense exists, so try to use it if possible.

the script below can help:

local jugador = game:GetService("Players").LocalPlayer --yield script

script.Parent.MouseButton1Click:Connect(function()
 workspace[jugador.Name].Head:WaitForChild("BillboardGui").TextLabel.Text = "hospital worker" --common sense
 workspace[jugador.Name].Head:WaitForChild("BillboardGui").TextLabel.TextStrokeColor3 = Color3.fromRGB(255, 0, 0) --you never used color3
end)
2 Likes

Someone litterally posted a similar solution op doesnt use it