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.
-- 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)
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!!
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