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

How to display a value that is within a character?

Hey, I am having trouble displaying a value located in the "workspace.Charactername" area. The following is what I have in a Local script that is within a text label.

local Clothingvlu = game.Players.LocalPlayer.Character.Clothing
local mode = "Bleh"--ignore
script.Parent.Text = "" ..Clothingvlu.Value.. " (P) of clothing."

When I run this I get the following error:

16:17:39.990 - Clothing is not a valid member of Model

16:17:39.991 - Script 'Players.Player.PlayerGui.TradeSystemGUI.ClothingAmount.Loca', Line 1

16:17:39.992 - Stack End

This is especially confusing because I can use this other script with no trouble at all: (Its not a local script)

function onButtonClicked()
--This gets the player who clicked and changes a value within the player
local h = script.Parent.Parent.Parent.Parent.Character.Clothing

h.Value = 101
print (h.Value)

end

script.Parent.MouseButton1Click:connect(onButtonClicked)

Help appreciated

1 answer

Assuming the first script is in their PlayerGui, the PlayerGui tends to load before the actual character. Use the WaitForChild method to well, wait for the child.

local Clothingvlu = game.Players.LocalPlayer.Character:WaitForChild('Clothing')
local mode = "Bleh"--ignore
script.Parent.Text = Clothingvlu.Value.. " (P) of clothing."

Another way is by adding a wait()

repeat wait() until game.Players.LocalPlayer.Character
local Clothingvlu = game.Players.LocalPlayer.Character
local mode = "Bleh"--ignore
script.Parent.Text = Clothingvlu.Value.. " (P) of clothing."

2 comments

0

Ok so I tried what you said and it gave me and error saying: WaitForChild called on an Instance that is not in a DataModel. So I thought about what you said and tried adding a wait(1) at the begging of the program and it worked, so in a way you helped me. Thanks!

0

No problem. You could also use repeat wait() to wait for the character. I'll update my answer

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