the next line underneath, the variable for the reward, 300/place
if you want to read the whole main server script then here you go, most of it is unrelated so i left it out
--This Script Manages the Main Game System
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
--Modules
local GroundModule = require(game:WaitForChild("ServerScriptService"):WaitForChild("TagManagement"):WaitForChild("GroundInfo"))
local ColorThemesInfo = GroundModule.ColorThemesInfo
local ColorThemesList = GroundModule.ColorThemesList
local MaterialThemesInfo = GroundModule.MaterialThemesInfo
local MaterialThemesList = GroundModule.MaterialThemesList
local MainEventModule = require(game:WaitForChild("ServerStorage"):WaitForChild("MainEventFolder"):WaitForChild("MainEventModule"))
local ThemeModule = require(game:GetService("ServerStorage"):WaitForChild("ThemesFolder"):WaitForChild("ThemesModule"))
--Variables
local levelsStorage = ReplicatedStorage:WaitForChild("Levels"):GetChildren()
local currentLevelsFolder = game.Workspace:WaitForChild("CurrentLevels")
local currentCheckpointsFolder = game.Workspace:WaitForChild("CurrentCheckpoints")
local lobby = game.Workspace:WaitForChild("Lobby"):WaitForChild("Lobby")
local lobbyCFrame = lobby:WaitForChild("End").CFrame
local LimitPart = game.Workspace:WaitForChild("Lobby"):WaitForChild("AfterWinLimitPart")
local winLevel = ReplicatedStorage:WaitForChild("WinLevel")
local checkpointLevel = ReplicatedStorage:WaitForChild("Checkpoint")
local winnersPodium = lobby:WaitForChild("PlayerWinners"):WaitForChild("WinnersPodium")
local firstPart = winnersPodium:WaitForChild("First")
local secondPart = winnersPodium:WaitForChild("Second")
local thirdPart = winnersPodium:WaitForChild("Third")
local isRound = game:WaitForChild("ServerStorage"):WaitForChild("IsRound")
local isFirstIntermission = true
local theme
local event
local competiviveModule = require(game:GetService("ServerScriptService"):WaitForChild("TagManagement"):WaitForChild("CompetitiveModule"))
--Animations
local dance1 = Instance.new("Animation")
dance1.AnimationId = "http://www.roblox.com/asset/?id=182435998"
local dance2 = Instance.new("Animation")
dance2.AnimationId = "http://www.roblox.com/asset/?id=182436842"
local dance3 = Instance.new("Animation")
dance3.AnimationId = "http://www.roblox.com/asset/?id=182436935"
local danceAnimList = {dance1, dance2, dance3}
--Amount of Levels
local amountOfLevels = 15
local checkpointDivide = math.floor(amountOfLevels/4)
--Materials for ground
local MaterialList = {"Metal", "Foil", "DiamondPlate", "Wood"}
--Remote Events Variables
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local fading = RemoteEvents:WaitForChild("Fading")
local PortalRemoteEvent = RemoteEvents:WaitForChild("Portal")
local modifierGuiUpdateEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("ModifierGuiEvents"):WaitForChild("ModifierGuiUpdate")
local modifierGuiUpdateDoneEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("ModifierGuiEvents"):WaitForChild("ModifierGuiUpdateDone")
--Debounces
local PortalDebounce = {}
local CheckpointDebounce = {}
--Round Variables
local roundStatus = ReplicatedStorage:WaitForChild("Status")
local intermissionLength = 3
local roundLength = 120
--Cleans up lobby
lobby:WaitForChild("Start").Transparency = 1
lobby:WaitForChild("End").Transparency = 1
--Level Sequence Function
local function levelSequence(totalLevelCount)
local lastLevelReference
--Creating Level Sequence
for level = 1, (totalLevelCount + 1), 1 do
--print("Loop Started")
local newLevel = levelsStorage[math.random(1, #levelsStorage)]:Clone()
--If first level then it starts in front of the lobby
if #currentLevelsFolder:GetChildren() == 0 then
--print("Loading First Level")
local lastLevel = Instance.new("BoolValue")
lastLevel.Name = "lastLevel"
lastLevel.Value = true
lastLevel.Parent = newLevel
newLevel.Parent = currentLevelsFolder
newLevel:PivotTo(lobbyCFrame)
newLevel:WaitForChild("Start"). Transparency = 1
newLevel:WaitForChild("End").Transparency = 1
lastLevelReference = newLevel
elseif level < (totalLevelCount + 1) then
--print("level other than first level")
for i, v in pairs(currentLevelsFolder:GetChildren()) do
if level == checkpointDivide or level == checkpointDivide * 2 or level == checkpointDivide * 3 then
--A checkpoint
if v:FindFirstChild("lastLevel") then
local newLevel = checkpointLevel:Clone()
newLevel.Parent = currentLevelsFolder
newLevel:PivotTo(v:WaitForChild("End").CFrame)
v:WaitForChild("lastLevel").Parent = newLevel
newLevel:WaitForChild("Start").Transparency = 1
newLevel:WaitForChild("End").Transparency = 1
--Configuring Checkpoint
local currentCheckpointPart = newLevel:WaitForChild("Checkpoint")
if level == checkpointDivide then
currentCheckpointPart.Name = "1"
elseif level == checkpointDivide * 2 then
currentCheckpointPart.Name = "2"
elseif level == checkpointDivide * 3 then
currentCheckpointPart.Name = "3"
end
currentCheckpointPart.Parent = currentCheckpointsFolder
lastLevelReference = newLevel
end
else
--Not a checkpoint
if v:FindFirstChild("lastLevel") then
newLevel.Parent = currentLevelsFolder
newLevel:PivotTo(v:WaitForChild("End").CFrame)
v:WaitForChild("lastLevel").Parent = newLevel
newLevel:WaitForChild("Start").Transparency = 1
newLevel:WaitForChild("End").Transparency = 1
if newLevel:FindFirstChild("Placements") then
for i, v in pairs(newLevel:WaitForChild("Placements"):GetDescendants()) do
if v:IsA("Part") then
v.Transparency = 1
end
end
end
lastLevelReference = newLevel
end
end
end
else
--Win Level
newLevel = winLevel:Clone()
newLevel.Parent = currentLevelsFolder
newLevel:PivotTo(lastLevelReference:WaitForChild("End").CFrame)
lastLevelReference:GetChildren("lastLevel").Parent = newLevel
newLevel:WaitForChild("Start").Transparency = 1
newLevel:WaitForChild("End").Transparency = 1
lastLevelReference = newLevel
end
end
end
--Function that clears all levels in currentLevelsFolder
local function clearLevels()
currentLevelsFolder:ClearAllChildren()
end
--Function that clears all checkpoints except spawn in currentCheckpointsFolder
local function clearCheckpoints()
for i, v in pairs(currentCheckpointsFolder:GetChildren()) do
if v.Name ~= "0" then
v:Destroy()
end
end
for i, plr in pairs(Players:GetPlayers()) do
plr:WaitForChild("leaderstats"):WaitForChild("Checkpoint").Value = 0
end
end
--Function that teleports player to spawn
local function teleportToSpawnWhenRoundEnd(plr, char)
plr:RequestStreamAroundAsync(currentCheckpointsFolder:WaitForChild("0").Position + Vector3.new(0, 2.5, 0))
char:FindFirstChild("HumanoidRootPart").CFrame = lobby:WaitForChild("Baseplate").CFrame * CFrame.new(0, 7, 0)
end
--Function that handles the competitive placement system rewards
local function competitivePlacementDisplay(plr)
--Variables
local place
local reward
--local err, success = pcall(function()
print(competiviveModule.competitivePlacements)
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
--Function that rewards the player
local function rewardPlayer(player, playerLeaderstats, isFirstIntermission)
if playerLeaderstats:WaitForChild("Checkpoint").Value > 0 and player.Team ~= Teams:WaitForChild("Winners") then
playerLeaderstats:WaitForChild("Cash").Value += 25 * playerLeaderstats:WaitForChild("Checkpoint").Value
elseif player.Team ~= Teams:WaitForChild("Winners") then
if isFirstIntermission == false then
print(player.Name .. " did not make any progress this round")
end
else
print(player.Name .. " has won this round already")
end
end
--Function that manages themes
local function applyThemes()
--Setup Themes
--local randomColorTheme = ColorThemesInfo[ColorThemesList[math.random(#ColorThemesList)]]
--local randomMaterialTheme = MaterialThemesInfo[MaterialThemesList[math.random(#MaterialThemesList)]]
--for i, object in pairs(CollectionService:GetTagged("Ground")) do
-- if object:IsDescendantOf(currentLevelsFolder) then
-- if #randomColorTheme ~= 0 and not object:FindFirstChild("SetBrickColor") then
-- object.BrickColor = BrickColor.new(randomColorTheme[math.random(#randomColorTheme)])
-- end
-- if not object:FindFirstChild("SetMaterial") then
-- object.Material = randomMaterialTheme[math.random(#randomMaterialTheme)]
-- end
-- end
--end
end
--Round System Functions
--Round Start System
local function roundStart()
isRound.Value = true
for i, player in pairs(Players:GetPlayers()) do
player.Team = Teams:WaitForChild("Obby")
end
roundStatus.Value = "Round Starting"
--Runs the levelSequence Function
levelSequence(amountOfLevels)
--Runs the applyThemes function
--applyThemes()
--Apply Theme
theme = ThemeModule.initialize()
if theme:FindFirstChildWhichIsA("ModuleScript") then
local specificThemeModule = require(theme:FindFirstChildWhichIsA("ModuleScript"))
specificThemeModule.start()
end
--Adds MainEvent
event = MainEventModule.initialize()
local module = require(event:FindFirstChildWhichIsA("ModuleScript"))
module.start()
--Modifier GUI
modifierGuiUpdateEvent:FireAllClients(module.title)
--LimitPart
LimitPart.CanCollide = false
for i = roundLength, 0, -1 do
if (i % 60) < 10 then
roundStatus.Value = "Time Remaining: " .. (i - (i % 60))/60 .. ":0" .. (i % 60)
else
roundStatus.Value = "Time Remaining: " .. (i - (i % 60))/60 .. ":" .. (i % 60)
end
wait(1)
if #Teams:WaitForChild("Obby"):GetPlayers() == 0 then
roundStatus.Value = "Everyone Finished!"
wait(1)
break
end
end
end
local function intermissionStart()
--Setting Variables
isRound.Value = false
--competitivePlacementReward()
--Checking if there was a previous round
if #currentLevelsFolder:GetChildren() > 0 then
--Removes Main Event
MainEventModule.remove(event)
local module = require(event:FindFirstChildWhichIsA("ModuleScript"))
module.stop()
--Removes Theme
ThemeModule.remove(theme)
if theme:FindFirstChildWhichIsA("ModuleScript") then
local specificThemeModule = require(theme:FindFirstChildWhichIsA("ModuleScript"))
specificThemeModule.stop()
end
--Modifier GUI
modifierGuiUpdateDoneEvent:FireAllClients()
--Clears Levels
clearLevels()
if roundStatus.Value ~= "Everyone Finished!" then
roundStatus.Value = "Game Ended!"
end
LimitPart.CanCollide = true
isFirstIntermission = false
--Clear podium from previous wins
for i, v in pairs (winnersPodium:GetChildren()) do
if v.Name ~= "Base" then
if v:FindFirstChildWhichIsA("Model") then
if v:FindFirstChildWhichIsA("Model"):FindFirstChild("HumanoidRootPart") then
v:FindFirstChildWhichIsA("Model"):Destroy()
end
v:FindFirstChild("SurfaceGui"):FindFirstChild("NameLabel").Text = ""
v:FindFirstChild("SurfaceGui"):FindFirstChild("NameLabel").Visible = false
end
end
end
for i, player in pairs(Players:GetPlayers()) do
--Podium Display
competitivePlacementDisplay(player)
end
end
--Reward Players and Respawn Players at Lobby
for i, player in pairs(Players:GetPlayers()) do
local playerLeaderstats = player:WaitForChild("leaderstats")
--Reward Players
rewardPlayer(player, playerLeaderstats, isFirstIntermission)
--Player's team is now the lobby
player.Team = Teams:WaitForChild("Lobby")
--Teleport player to spawn
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
if humanoid then
local success, err = pcall(teleportToSpawnWhenRoundEnd, player, char)
if not success then
warn("Attempt to teleport player to lobby, wait for player to reset for player to be spawned at lobby")
end
end
--Podium Display
--competitivePlacementDisplay(player)
end
--Make actual values back to default
competiviveModule.competitivePlacements = {}
print(competiviveModule.competitivePlacements)
--Checkpoint Removal
clearCheckpoints()
--LimitPart
LimitPart.CanCollide = true
wait(3)
for i = intermissionLength, 0, -1 do
if i == 0 then
roundStatus.Value = "Game Starting!"
else
roundStatus.Value = "Game Starting In... " .. i .. " Seconds"
end
wait(1)
end
end
--Main Round Function
local function mainGame()
while true do
intermissionStart()
roundStart()
wait()
end
end
--Runs The Main Game Function
spawn(mainGame)
Also for some reason i put the module variable separate from the other module variables, but it doesnt change anything
so ur trying to do it with the place thing that means we are back onto square 1 i honestly dont know what to do rather than try to see about when u set that value in the table
A few examples:
How do you go about returning functions in a Module Script?
How can I get variables from a Module Script?
Help with getting a value from module script.
I think I found the problem.
When I play with multiple players:
When I reference the table competiviveModule.competitivePlacements
, it prints this:
placements list
{
[-2] = 1,
[-1] = 1
}
When I index that table, it is nil (of course no one has a negative user id): competiviveModule.competitivePlacements[plr.UserId]
The list should print:
[first place user id] = 1
[second place user id] = 2
etc.
oh wow what the heeeell did u fix it thogh?
I’m currently trying to figure it out
okay dummy hope u figure it out
You’re doing fine. We all start out this way. Keep in mind how well you can research your questions is something every programmer has to an expert at. One of a programmers strongest skills.
There is far too much to learn. At some point knowing where to find your answers overrides your memory. Also keep personal notes on techniques. They will in time become your personal programming bible.
Whenever there is only 1 player, the table works as expected, but only with one player of course
module.competitivePlacements[plr.UserId] = #(module.competitivePlacements) + 1
This is the problem, nothing gets added with this line of code. This is a dictionary i think
When I print: print(#(module.competitivePlacements))
before and after the line of code above, before it gets added it is 0, and after it is added it is still 0, so nothing actually gets added to the table/dictionary.