I’m making a renting system, and right now, I’m trying to make is so that a player can’t rent a room if another player is already renting it. When a player rents a room, their userId is stored in a table with a value of the door. It looks like this:
local doorTable = {
123456789 = door
}
When they run out of time, they get removed from the table. To check if anyone is renting the room, I’m using table.find to find the index of the door. Here is the script:
local function isRoomBeingUsed(player, doorObject)
local beingUsed = table.find(doorTable, doorObject)
return beingUsed
end
fireIsRoomUsed.OnServerInvoke = isRoomBeingUsed()
Here’s the local script that prompts the player to rent the room:
tech60.MouseButton1Click:Connect(function()
print("tech60 activated")
local beingUsed = fireIsRoomUsed:InvokeServer(tech)
if not beingUsed then
MarketplaceService:PromptProductPurchase(LocalPlayer,1353158718)
print("prompted")
else
print("being used")
end
end)
-- there are a lot more, I just repeat this for each room
For some reason, I’ll click the door to rent the room, and it’ll print “tech60 activated”, but I won’t print “prompted” or “being used”. What’s the issue here?
You need to add an object value or something into each room and set it to the player, and then, detect if the value is being used or not. If not, allow them to rent.
Oh So will it just be best to do what @SubtotalAnd8185 said? To set an object value of each door to the player while renting? I guess this would also make it so I would’nt have to use remote functions.
I have low confidence in object values, however you can still use tables. Just like the example code I provided, you can simply use the door objects themselves as the key.
If the room is vacant, remove the door from the table.
If a room has been rented, add the door to the table as a key, and the value can be the ID of the player, or a table with the player ID (and some other stuff you want to add.