Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to display a value that is within a character?

Asked by 10 years ago

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

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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."
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! lordrex12345 25 — 10y
0
No problem. You could also use repeat wait() to wait for the character. I'll update my answer Shawnyg 4330 — 10y
Ad

Answer this question