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

attempt to call a number value?

Asked by 2 years ago
local t = script.Parent
local plr = t.Parent.Parent.Parent
plr:WaitForChild("stats")
local l = plr.leaderstats.level
local e = plr.stats.exp
while true do
    t.Text = "Level "..l.Value": "..e.Value"/50"
end

attempt to call a number value (line7) anyonehelp?

0
accidently posted it on alt standingmcdonalds is my main for when I reply User#32519 0 — 2y
0
try t.Text = "Level "..l.Value..": "..e.Value.."/50" boqueburro 57 — 2y

1 answer

Log in to vote
1
Answered by
TGazza 1336 Moderation Voter
2 years ago
Edited 2 years ago

Quite a few bugs in this code. On line 6 your While loop has no wait() in it, this will cause this script to hang and error out also some formatting in your text string is malformed.

This is the correct code that should run:

local t = script.Parent
local plr = t.Parent.Parent.Parent
plr:WaitForChild("stats")
local l = plr.leaderstats.level
local e = plr.stats.exp
while wait() do -- wait a game tick each loop wait() returns true once it's done waiting!
    t.Text = "Level "..tostring(l.Value)..": "..tostring(e.Value).."/50" -- the tostring() function just simply makes sure we're dealing with a string and not a nil, So even in some Value comes back as nill it will print a string nil!.
end

Also the error is erroring out with a Number value because you're trying to join a string and a number together to form a string. The above example should sort this out! EG:

local v = "some text ["..( 1 ).. "] woot!"

this would be ok with code but Text fields in guis only accept strings(text) so to help thi compute i would change this to...

local v = "some text ["..tostring( 1 ).. "] woot!"

Hope this helps! :)

Ad

Answer this question