Hi you all. I’m developing an obby game with a round system, and there is a placement system (1st place, 2nd place, etc.)
For some reason, one specific part of the placement system does not work, because the list is nil. When I actually print it in the module script, it prints the list, so I don’t know why it is nil in another server script referencing it. I tried finding out if something was in the wrong order, but I couldn’t find out what to do.
Here is the part where it says it is nil:
place = competiviveModule.competitivePlacements[plr.UserId] --Where it returns nil
Well here is the actual code:
When Round Ends (Part of Server Script)
--Function that handles the competitive placement system rewards
local function competitivePlacementDisplay(plr)
--Variables
local place
local reward
local err, success = pcall(function()
place = competiviveModule.competitivePlacements[plr.UserId]
reward = math.ceil(300/place)
print(reward)
print(place)
end)
if not success then
warn(plr.Name .. " placement data not loaded")
end
--Placements will be shown to all players with a GUI
competiviveModule.competitivePlacementsGuiDisplay(plr, isFirstIntermission)
--Checks if the player should go onto the winners podium
if place and (place <= 3) then
local top3List = {
[1] = firstPart,
[2] = secondPart,
[3] = thirdPart
}
--Variables
local podiumPart = top3List[place]
local positionPart = podiumPart:WaitForChild("PositionPart")
local nameLabel = podiumPart:WaitForChild("SurfaceGui"):WaitForChild("NameLabel")
--Get the player's character
local character = plr.Character or plr.CharacterAdded:Wait()
local newCharacter
if character then
character.Archivable = true
newCharacter = character:Clone()
character.Archivable = false
newCharacter.Parent = podiumPart
end
local humanoid
local humanoidRootPart
if newCharacter then
humanoidRootPart = newCharacter:FindFirstChild("HumanoidRootPart")
humanoid = newCharacter:FindFirstChild("Humanoid")
--Apply Character to podium
humanoidRootPart.CFrame = positionPart.CFrame
humanoidRootPart.Anchored = true
nameLabel.Text = plr.Name
nameLabel.Visible = true
--Animate Character
local danceAnimation = danceAnimList[math.random(1,3)]
local animator = humanoid:WaitForChild("Animator")
local danceTrack = animator:LoadAnimation(danceAnimation)
danceTrack:Play()
end
end
end
When function is called:
--Reward Players and Respawn Players at Lobby
for i, player in pairs(Players:GetPlayers()) do
--(Other code was here not related to this question)
--Podium Display
competitivePlacementDisplay(player)
end
Module
local module = {
competitivePlacements = {},
displayProperties = {
[1] = {"1st", Color3.fromRGB(255, 184, 70)},
[2] = {"2nd", Color3.fromRGB(239, 239, 239)},
[3] = {"3rd", Color3.fromRGB(197, 121, 70)},
[4] = {"4th", Color3.fromRGB(113, 113, 113)},
[5] = {"5th", Color3.fromRGB(113, 113, 113)},
[6] = {"6th", Color3.fromRGB(113, 113, 113)}
}
}
function module.competitivePlacementsManagement(plr)
module.competitivePlacements[plr.UserId] = #(module.competitivePlacements) + 1
print(module.competitivePlacements)
local place = module.competitivePlacements[plr.UserId]
local reward = math.ceil(300/place)
return reward
end
function module.competitivePlacementsGuiDisplay(plr, isFirstIntermission)
--Variables
local WinGuiDisplayEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("WinDisplayEvents"):WaitForChild("WinGuiDisplay")
local WinGuiVisibleEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("WinDisplayEvents"):WaitForChild("WinGuiVisible")
local PlacementFrame = plr:WaitForChild("PlayerGui"):WaitForChild("WinnersGui"):WaitForChild("PlacementFrame")
if not isFirstIntermission then
if module.competitivePlacements[plr.UserId] then
local place = module.competitivePlacements[plr.UserId]
local info = module.displayProperties[place]
print(place)
print(info)
WinGuiDisplayEvent:FireClient(plr, info[1], info[2])
print("placements list")
end
WinGuiVisibleEvent:FireClient(plr, PlacementFrame)
else
print("First Intermission, no placements list")
end
end
return module
When player enters the portal that makes you win (Part of a different module script which gets ran in a Server Script)
--Rewarding Players for Winning
local reward = competiviveModule.competitivePlacementsManagement(player)
--Just know that there is a lot of unrelated code that I'm just not showing, so just know that this variable is declared when the player reaches the end portal.
Thank you all for helping