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

Problems with variables?

Hi,

i make a Script that checks if a Hotel Room is in use or not. There is a TextBox with the name "roomnumberhere" and a button. And there is a Model with the name "freiezimmer", in this model are boolvalues (true = in use, false = not in use). In the TextBox you enter the Number of the Room. That's my code:

script.Parent.MouseButton1Down:connect(function()
	local roomnumber = script.Parent.Parent.roomnumberhere.Text
	local checkvalue = game.Workspace.freiezimmer.roomnumber
	print("working")
end)

If i press the Button nothing happens, it just say: roomnumber is not a valid Member of Model. It says the Problem is in Line 3.

1 answer

✓ Accepted answer

You're looking for an object/item named 'roomnumber' when you should be looking for an object that matches the variable. You can use FindFirstChild to find an object which matches the text:

script.Parent.MouseButton1Down:connect(function()
    local roomnumber = script.Parent.Parent.roomnumberhere.Text
    local checkvalue = game.Workspace.freiezimmer:FindFirstChild(roomnumber)
    print("working")
end)

7 comments

0

And after that i can do something like: if checkvalue.Value == true then ....?

0

Yes. Though I would recommend adding in some string.match checks to see if it's even a number, otherwise it'll throw errors if the player tries to input letters and such.

0

Is there a Wiki Post about that? I'm bad at scripting.

0

And how can i use that? If it gets to long, send me a Roblox Message.

0

if string.match(roomnumber, "%a") or string.match(roomnumber, "%p") then print("Those aren't numbers!") end You'd replace the print with however you want to handle that. I prefer setting it back to the previous number in this event.

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