Unable to assign property Text. string expected, got Instance - lua

I was making random text script (dont mind the sounds thing) and I got this error: Unable to assign property Text. string expected, got Instance.
while thing == true do
wait(math.random(3, 12))
local txts = game.ServerStorage.CallTexts:GetChildren()
local Choices = script:GetChildren()
local RandomIndex = math.random(1, #Choices)
local RandomSound = Choices[RandomIndex]
local RandomTextIndex = math.random(1, #txts)
local RandomText = Choices[RandomTextIndex]
RandomSound:Play()
game.Workspace["Talking Ben's Room"].furniture.desk.phone["De Text"].BilBord.toxt.Text = RandomText
wait(RandomSound.TimeLength)
end

Text should be a string. RandomText is an Instance. Like the error told you. What type are the Choices, e.g. the children of CallTexts? Do they have a getter/toString?
If they are StringValues you will need RandomText.Value
If they are TextLabels (your case), you will need RandomText.ContentText

Related

attempt to index a boolean value (local 'target')

I have looked at different ways to fix this but have no understanding at all. I've tried fixing the code in every was possible and still have no success.
RegisterServerEvent('housing:attemptsale')
AddEventHandler('housing:attemptsale',
function(args,price,hid,model)
local src = source
local user = exports["np-base"]:getModule("Player"):GetUser(src)
local char = user:getCurrentCharacter()
local target = exports["np-base"]:getModule("Player"):GetUser(args)
local targetchar = user:getCurrentCharacter()
if target:getCash() >= price then
target:removeMoney(price)
exports.ghmattimysql:execute("UPDATE houses SET `cid` = #cid, `price` = #price, `model` = #model WHERE `id` = #id", {
['#cid'] = targetchar.id,
['#price'] = price,
['#id'] = hid,
['#model'] = model
})
else
TriggerClientEvent('DoShortHudText', args, 'You dont got money', 2)
end
end)
As you did not provide any resources on those functiosn you're using there is not much we can do for you.
Actually this is pretty simple.
You're indexing a boolean value local target.
That means your doing something like target:something(), target.something, target[something].
Here you create target:
local target = exports["np-base"]:getModule("Player"):GetUser(args)
Then you do this target:getCash(). At this point target is a boolean, that means it is either true or false.
So you know exports["np-base"]:getModule("Player"):GetUser(args) returned true or false.
Now you have two options.
find out why the function returns a boolean and not what you expect and fix that
don't index target if target is not indexable.

I need help to fix this code, Can someone say why isnt this working?

Im trying to add pictured menu ,but it gives me error.Error, .lua
function loadPlayerInventory()
TBCore.Functions.TriggerServerCallback('tb-inventory:server:getPlayerInventory', function(data)
items =
inventory = data.inventory
weapons = data.weapons
local weight = 0
if inventory ~= nil then
for k, v in pairs(inventory) do
table.insert(items, inventory[k])
weight = weight + (inventory[k].amount * inventory[k].weight)
end
items =
should give you an error "unexpected symbol near = So you should not even get to that point that your callback is called.
You forgot to assign a value to items. Your code suggests that it should be a table.
The error in the screenshot is caused by indexing data, a local nil value.
inventory = data.inventory
This is because your callback is called but no parameter data is given. Find out why or make sure you don't index it if it is nil.
Something like
if data then
inventory = data.inventory
end
or
inventory = data and data.inventory
for example

How to access user typed text inside a text box to make it as a variable? (Roblox)

So, I want to make a converter GUI, converting Bitcoin to Dollar. I use a textbox to get the user input and a text button to submit. But, when I type number for example 8 to the textbox while test the game and print what is inside the textbox, it printed nothing. Even though I have type 8 to the text box. Thanks for all the answers! Here is the code I use.
-- text variable below
local input = script.Parent
local val = input.Text
-- button variable below
local submit = input:FindFirstChild("btcSubmit")
-- player variable below
local gams = game.Players.LocalPlayer
local ld = gams:WaitForChild("leaderstats")
local bitcoin = ld:WaitForChild("Bitcoin").Value
local dollar = ld:WaitForChild("Dollar").Value
-- function
function btcEx()
val = tonumber(val)
if val > bitcoin then
val = tostring(val)
val = "Sorry, your Bitcoin isn't enough"
wait(4)
val = "Input the number of bitcoin you want to exchange here!"
else
dollar = val * 8000
val = tostring()
end
end
submit.MouseButton1Click:Connect(btcEx)
When you set a variable to a value rather than a reference, it remains that value until you change it.
object.Value = 5
local myValue = object.Value
object.Value = 10
print(myValue) -- Prints 5.
This happens because they are not linked and thus changes do not carry over, like these variables below:
local a = 5
local b = a
a = 10
print(b) -- Prints 5, because b was never changed (but a was).
What you want to do is define your button and your value-objects as references, and simply access .Text or .Value when you need to read the value.
local myButton = button
button.Text = "Howdy!"
print(myButton.Text) -- Prints "Howdy!"
myButton.Text = "Hey there" -- this is the same as button.Text
print(myButton.Text) -- Prints "Hey there"

How to update a variable in corona SDK?

I have a function, which changes the variable from what it was to something new. I am using load-save .json tables to get and load data. How do I update the startmoneyTxt to display the new variable?
My function:
local function unlockBall(event)
ballfirst = loadsave.loadTable("firstBall.json", system.DocumentsDirectory)
currentMoney1 = loadsave.loadTable("cashTable.json", system.DocumentsDirectory)
difference = currentMoney1 - ballfirstUnlock
if(ballfirst == 0 and difference >= 0)then
ballfirstID = 1
loadsave.saveTable(ballfirstID, "firstBall.json", system.DocumentsDirectory)
loadsave.saveTable(difference, "cashTable.json", system.DocumentsDirectory)
end
end
My code which should be updated:
currentMoney = loadsave.loadTable("cashTable.json", system.DocumentsDirectory)
startmoneyTxt= display.newText("$ "..currentMoney.." " , 0,0, "Helvetica", 20)
sceneGroup:insert(startmoneyTxt)
Whenever you want change text use
startmoneyTxt.text = "Your text here"
Note: As names saveTable and loadTable imply functions are indent to save/load tables. So you can use one file to save/load multiple values.
I use loadsave module to save/load setings in my game The Great Pong.

Attempt to concatenate global 'q101' (a nil value)

i like to load text form a external .lua file in to my game, here is a little test i setup to test the principal, i know if i give "q101" numbers like so "q101 = 123456" the code displays the numbers 123456 but i don't understand why it doesn't with letters.
Can some one please explain how i can do this is the right way, as this is clearly not the way of doing it
q101 = HELLO
Q1 = display.newText("".. q101, 160, 20, MYRIADPRO, 30)
Q1:setTextColor( 255, 255, 2552)
Q1.x = display.contentWidth/2
Q1.y = display.contentHeight/2
screenGroup:insert(Q1)
This line q101 = HELLO is setting the value of the q101 variable to the value of the HELLO variable. And as the global variable with that name has no value (as it has never been defined) you are assigning nil to your q101 variable.
Numbers cannot be variables and so do not work that way.
You want to assign the string "HELLO" to your variable: q101 = "HELLO".

Resources