Claim Table Scripts

Hello!

I’m making a jigsaw puzzle game and I’m having trouble with some warnings I’ve been getting.

Each table has a proximity prompt that when activated, it stores claimed table information. The proximity prompt should then be disabled (but it doesn’t when I run the game) if a player has a claimed table to their user Id. Then, the player can click the generate puzzle button and it will be generated at the claimed table location.

My script structure and usage:

1. ClaimTableModule:

  • Location: ReplicatedStorage/ClaimTableModule
  • Purpose:
    • Manages the claimed tables, storing information about which tables are claimed by which players.
    • Provides functions like getPlayerClaimedTableInfo, claimTable, and waitForTableClaim to interact with and retrieve information about claimed tables.

2. ClaimTableScript (Client):

  • Location: LocalScript inside StarterPlayer > StarterPlayerScripts
  • Purpose:
    • Handles the claiming of tables when a player triggers a proximity prompt.
    • Connects to the ClaimTableModule to claim tables and obtain information about the claimed tables.
    • Disables the ProximityPrompt associated with the claimed table.

3. ClaimTableEvent (Server):

  • Location: ReplicatedStorage/ClaimTableEvent
  • Purpose:
    • A RemoteEvent used to communicate between the client and the server when a table is claimed. It carries information about the claimed table.

4. ClaimTableScript (Server):

  • Location: ServerScriptService/TableClaimingScript
  • Purpose:
    • Listens for the ClaimTableEvent triggered by the client.
    • Calls functions in the ClaimTableModule to process table claiming on the server side.
    • Additional server-side actions when a table is claimed.

5. PuzzleGenerationModule:

  • Location: ReplicatedStorage/PuzzleGenerationModule
  • Purpose:
    • Defines functions related to puzzle generation.
    • Uses a BindableEvent (ClaimedTableEvent) to receive information about claimed tables.
    • The generatePuzzle function is called when a puzzle needs to be generated.

6. PuzzleGenerationScript (Server):

  • Location: ServerScriptService/PuzzleGenerationScript
  • Purpose:
    • Listens for the ClaimedTableEvent and triggers the generatePuzzle function in the PuzzleGenerationModule when a table is claimed.

7. PuzzleGenerationScript (Client):

  • Location: LocalScript inside StarterPlayer > StarterPlayerScripts
  • Purpose:
    • Connects to the GeneratePuzzleEvent to notify the server when a puzzle needs to be generated.

It seems to me that everything is working fine but then I get these warnings in the output:

Let me know if you want to see a specific script as there are a couple of them…

1 Like

Can you send the script where the warning occurs?

1 Like

Here it is

-- PuzzleGenerationScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local GeneratePuzzleEvent = ReplicatedStorage:WaitForChild("GeneratePuzzleEvent")
local ClaimTableModule = require(game.ReplicatedStorage:WaitForChild("ClaimTableModule"))

-- Function to generate the puzzle
function generatePuzzle(player)

	local claimedTablePosition = ClaimTableModule.getPlayerClaimedTableInfo(player)
	
	if claimedTablePosition then
		local jigsawPiecesFolder = ReplicatedStorage:WaitForChild("jigsaw_test1")
		local correctSnapPositionsFolder = ReplicatedStorage:WaitForChild("CorrectSnapPositions")

		local jigsawPieceModels = jigsawPiecesFolder:GetChildren()

		if #jigsawPieceModels > 0 then
			for _, jigsawPieceModel in ipairs(jigsawPieceModels) do
				local randomX = math.random()
				local randomY = math.random()
				local randomZ = math.random()

				local randomPosition = claimedTablePosition + Vector3.new(randomX, randomY, randomZ)

				local randomJigsawPiece = jigsawPieceModel:Clone()

				if randomJigsawPiece:IsA("MeshPart") then
					randomJigsawPiece.CFrame = CFrame.new(randomPosition)
				else
					warn("Invalid object type:", randomJigsawPiece.ClassName)
				end

				randomJigsawPiece.Parent = Workspace
			end
		else
			warn("No jigsaw piece models found in ReplicatedStorage.")
		end
	else
		warn("Player does not have a claimed table.")
	end
end

-- Connect the generatePuzzle function to the RemoteEvent
GeneratePuzzleEvent.OnServerEvent:Connect(generatePuzzle)
1 Like

Looking back at your original post, you say that everything seems to be working fine. If everything’s working fine, why do you think that this warning poses a problem?

Well the proximity prompt should be getting disabled after the player claims a table but it’s still there. I think for some reason the claimed table information is not getting properly registered or stored in the claim table module, that’s why I’m concerned about the warnings. Here is the module btw.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClaimedTableEvent = ReplicatedStorage:FindFirstChild("ClaimTableEvent")

local ClaimTableModule = {}
local claimedTables = {} -- Store claimed tables with player UserId and table name

function ClaimTableModule.getPlayerClaimedTableInfo(player)
	local userId = tostring(player.UserId)
	claimedTables[userId] = claimedTables[userId] or {}

	if claimedTables[userId].tableName then
		return claimedTables[userId].tableName, claimedTables[userId].position
	else
		print("No claimed table information found for player with UserId:", userId)
		return nil, nil
	end
end

function ClaimTableModule.claimTable(player, tableName, tablePosition)
	local userId = tostring(player.UserId)
	claimedTables[userId] = claimedTables[userId] or {}

	if not claimedTables[userId].tableName then
		print("Claiming table for player with UserId:", userId)
		claimedTables[userId] = {
			tableName = tableName,
			position = tablePosition
		}
		-- Notify about the claimed table using the event
		ClaimedTableEvent:Fire({ playerName = player.Name, tableName = tableName, position = tablePosition })
		return true
	else
		print("Player with UserId", userId, "already claimed a table.")
		return false
	end
end

function ClaimTableModule.waitForTableClaim(player, timeout)
	timeout = timeout or 30  -- Default timeout value in seconds

	local startTime = tick()
	while not claimedTables[player.UserId] and (tick() - startTime) < timeout do
		wait(1)  -- Wait for 1 second before checking again
	end

	return ClaimTableModule.getPlayerClaimedTableInfo(player)
end

return ClaimTableModule

What do you mean by disabled? Do you mean that it shouldn’t run at all or that the function should be returned if the player has already claimed a table? Looking at the code you sent me, you should print the player’s claimed table, and see if the data matches up correctly.

Ok so I’m getting a new error now… I think it’s because somewhere between claiming a table and clicking the generate puzzle button, the player’s data becomes nil. I’ve used print:(type(player)) and it’s given me a nil value.
Btw, the proximity prompt works now.

Pls help I’ve been stuck on this error for a couple days now. I’ve ruled out any syntax or spelling errors, so I’m not sure what’s going on. Thank you!!

This is the script that is causing the error.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mainmenu = script.Parent.Parent
local puzzlecam = mainmenu.Parent.ReturnToPuzzle
local puzzlesettings = mainmenu.Parent.PuzzleSettings1

local generateButton = mainmenu:FindFirstChild("GeneratePuzzleButton")
local GeneratePuzzleEvent = ReplicatedStorage.PuzzleGenerationModule:FindFirstChild("GeneratePuzzleEvent")
local ClaimTableModule = require(ReplicatedStorage.ClaimTableModule)

if not player then
	player = Players.PlayerAdded:Wait() -- Wait for the LocalPlayer to be added
end

if not player or not player:IsA("Player") or not player.Parent then
	warn("Invalid LocalPlayer.")
	return
end

generateButton.MouseButton1Click:Connect(function()
	local claimedTable, position = ClaimTableModule.getPlayerClaimedTableInfo(player)
	print(type(player))

	if claimedTable then
		print(player.Name .. " has claimed the table: " .. claimedTable)
		wait(1) -- Introduce a delay before attempting to retrieve claimed table information
		print(type(player))

		local updatedClaimedTable, updatedPosition = ClaimTableModule.getPlayerClaimedTableInfo(player)

		print("Attempted to get updated claimed table:", updatedClaimedTable)

		if updatedClaimedTable then
			print(player.Name .. " has a claimed table: " .. updatedClaimedTable)
			-- Additional logging if needed
			if GeneratePuzzleEvent then
				GeneratePuzzleEvent:FireServer(player, updatedPosition)
			else
				warn("GeneratePuzzleEvent not found.")
			end
			-- Additional logic for showing/hiding UI elements
			puzzlesettings.Visible = true
			mainmenu.Visible = false
			puzzlecam.Visible = true
		else
			warn(player.Name .. " does not have a claimed table.")
		end
	else
		warn(player.Name .. " does not have a claimed table.")
	end
end)

It doesn’t make sense that the error is happening on the GenerateButton script. Usually when passing a nil value through a function(assuming the nil value is the problem), the code where the function is will error, and not where you’re passing it through. Have you checked that you’re calling the right function/using the correct module script? You might need to do a WaitForChild on the ClaimTableModule.

I finally fixed it! I wasn’t correctly requiring the modules and also I needed to add creation of new remote events. I also split up the module into client side and server side functions which helped a lot into figuring out the problem. Thank you for your help :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.