01 | local hasroom = false |
02 | local debounce = true |
03 | local roomname = "Room" |
04 | while true do |
05 | wait() |
06 | debounce = true |
07 | local plr = game.Players.LocalPlayer |
08 | for i,v in pairs (game.Workspace.Rooms:GetChildren()) do |
09 | local ownr = v:FindFirstChild( "plrowner" ) |
10 | if ownr then |
11 | if ownr.Value = = plr.Name then |
12 | if debounce = = true then |
13 | hasroom = true |
14 | debounce = false |
15 | roomname = v.Name |
So, there are 3 hotel rooms. In each hotel room is a value with the name of the player who owns it. In this GUI I want it to say what hotel room you're in if it detects a hotel room with your name in the owner value, or to say that you're in no hotel room if there isn't a hotel room with your name in the owner value. The issue is that it doesn't work all too well. It only works if you're in room 3 (the last room), but if you're in room 1 or 2 it always says you don't have a room. Some help please?
It isn't working in rooms 1 or 2 is because of your else statement on line 17.
Your code makes it so if the current room iteration's owner is not the localplayer, it will put 'hasroom' to false. This is a problem because if the player's room is 1 or 2 the code will set 'hasroom' to true, go to the next room and see the player does not own it, then return 'hasroom' back to false.
This is the reason for it only working when you own room 3, because there are no rooms ahead to check. And therefore, the code cannot reset 'hasroom'.
So, to fix this.. basically remove the whole else statement from your code and you should be good.
P.S - debounce isn't necessary here. It just clutters the code since it isn't actually controlling anything.
01 | local plr = game.Players.LocalPlayer |
02 | local hasroom = false |
03 | local roomname = "Room" |
04 |
05 | while wait() do |
06 | for i,v in pairs (workspace.Rooms:GetChildren()) do |
07 | local ownr = v:FindFirstChild( "plrowner" ) |
08 | if ownr then |
09 | if ownr.Value = = plr.Name then |
10 | hasroom = true |
11 | roomname = v.Name |
12 | --The 'break' statement stops loops |
13 | break |
14 | --Since 'hasroom' is already true, break the loop |
15 | end |