I have printed in many different ways. In the table when I do print(table[0]) and print(table[1]) they both return nil. Here is the code:
local chatrooms = {
UnnamedVoiceChat = 'OwnerName'
}
renameroom.OnServerEvent:Connect(function(player, newname)
if player.RoomOwnership.Value == nil then
return error('Player Owns Nil')
else
print(player.RoomOwnership.Value) -- UnnamedVoiceChat - Server - ChatRooms:24
local index = table.find(chatrooms,player.RoomOwnership.Value)
if index == nil then
return error('Could Not Find Index') -- Calls Error in Console
else
local room = chatrooms[player.RoomOwnership.Value]
chatrooms[index] = nil
chatrooms[newname] = chatrooms[index]
chatrooms[newname] = player.Name
renameroom:FireAllClients(player,room,newname)
end
end
end)
table.find always returns nil when you’re using it with a dictionary.
It looks like you’re checking if a key exists in chatrooms. You can do that by just indexing chatrooms and checking if that’s nil. Here’s an example (I rewrote your repossess connection):
repossess.OnServerEvent:Connect(function(player, room)
if chatrooms[room] ~= nil then
error()
else
player.RoomOwnership.Value = room
chatrooms[room] = player.Name
repossess:FireAllClients(room, player)
end
end)
renameroom.OnServerEvent:Connect(function(player, newname)
if player.RoomOwnership.Value == nil then
return error('Player Owns Nil')
else
print(player.RoomOwnership.Value)
local key = chatrooms[player.RoomOwnership.Value]
if key == nil then
return error('Could Not Find Key')
else
chatrooms.newname = key
renameroom:FireAllClients(player,key,newname)
key = nil
end
end
end)
this: local key = chatrooms[player.RoomOwnership.Value] is still nil i dont know whats going on. It already exists under the value and table I checked.
Take a screenshot or copy and paste the output of the print statements here (do print(chatrooms) and print(player.RoomOwnership.Value). If the key-value pair exists in the dictionary, it shouldn’t return nil.
player.RoomOwnership.Value is “For Sauce”, which doesn’t exist in the dictionary, so it’s returning nil. The problem, then, lies in some other area of your script where you set the room ownership value, so I’d suggest looking there. Maybe you forgot to update the dictionary when someone creates a room?