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

Problems with variables?

Asked by
OKRPLAY 25
8 years ago

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

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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)

0
And after that i can do something like: if checkvalue.Value == true then ....? OKRPLAY 25 — 8y
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. Pyrondon 2089 — 8y
0
Is there a Wiki Post about that? I'm bad at scripting. OKRPLAY 25 — 8y
View all comments (3 more)
0
And how can i use that? If it gets to long, send me a Roblox Message. OKRPLAY 25 — 8y
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. Pyrondon 2089 — 8y
Ad

Answer this question