I need help with boss award system

Hello developers, I need help. I am creating a remake of the game Mega Boss Survival (By @Dinpey).


What Is This?

“Mega Boss Survival” is a popular game on Roblox created by the developer @Dinpey. In this game, players face off against powerful bosses in a survival setting, where they must work together with others to defeat these formidable enemies. The gameplay typically involves strategic planning, teamwork, and the use of various weapons and tools to survive and conquer the bosses. If the current player survives the boss, then he gets a certain number of points and one survival. And if he doesn’t survive, he gets nothing.


Problem:

When a player survives, he does not get points and survival, while for some reason it does not work for a certain number of bosses, that is, some give points and survival, while others do not.

Each boss has an Attribute for a certain number of points (NumberValue) and an Attribute for a certain amount of time, how long he will be in the workspace (NumberValue) (All bosses are in a folder in the ServerStorage!)

Bosses appear randomly with intermission 20 seconds

ALSO BOSS DISAPPEARING BEFORE THEN TIMER IS ENDS! (Like 2-3 second left and boss just disappear and function ends)

Script sequence:

Summary

Intermission/Countdown (20 seconds) → A random boss is selected → The boss is copied to the workspace (when Intermission/Countdown = 0) → The boss timer starts, which can have any value (from 0 seconds to infinity) → When the boss timer ends, two things happen:

→ The boss is removed from the workspace (Destroy() )
→ If the player survives the boss, then he gets a certain number of points and one survival, if not, then the player does not get anything.

After all this, the Intermission/Countdown (Cycle) starts again

Full Script for help:


Full Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local tweenService = game:GetService("TweenService")

local IntermissionMusicEnabled = true
local DelayToStopTheIntermissionMusic = 1
local IntermissionMusicList={
	1840684377,-- music name: Diamonds
	1837066593,-- music name: Easy Mover
	1842241530,-- music name: Lazy Sunday
	1846458016,-- music name: No more
	1840684208,-- music name: Playground Of The Stars (A)
	1838857104,-- music name: Roselita
	1845458027,-- music name: Smooth Nylons
	1846457890,-- music name: Solitaire
	1845756489,-- music name: Town Talk
	11113863191, 
}

local updateCountdownEvent = ReplicatedStorage:WaitForChild("UpdateCountdown")
local updateTimerEvent = ReplicatedStorage:WaitForChild("UpdateTimer")
local updateDifficulty = ReplicatedStorage:WaitForChild("UpdateDifficulty")
local TableName = {}

local countdownTime = 20 -- Changeable countdown time
local killersFolder = ServerStorage:WaitForChild("Killers")

--[[local function rewardSurvivors(points)
	print(TableName)
	for _, player in TableName do
		if player and player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
			local leaderstats = player:FindFirstChild("leaderstats")
			if leaderstats then
				local survivals = leaderstats:FindFirstChild("Survivals")
				local playerPoints = leaderstats:FindFirstChild("Points")
				if survivals and playerPoints then
					survivals.Value = survivals.Value + 1
					playerPoints.Value = playerPoints.Value + points
				end
			end
		end
	end
end-]]


local function rewardSurvivors(points)
	print(TableName)
	for _, player in TableName do
		local Players = game:GetService("Players")
		for _, player in Players:GetPlayers() do
			if player and player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
				local leaderstats = player:FindFirstChild("leaderstats")
				if leaderstats then
					local survivals = leaderstats:FindFirstChild("Survivals")
					local playerPoints = leaderstats:FindFirstChild("Points")
					if survivals and playerPoints then
						survivals.Value = survivals.Value + 1
						playerPoints.Value = playerPoints.Value + points
					end
				end
			end
		end
	end
end



local function spawnRandomKiller()
	local killers = killersFolder:GetChildren()
	if #killers == 0 then return end

	local randomKiller = killers[math.random(1, #killers)]
	local killerClone = randomKiller:Clone()
	killerClone.Parent = workspace

	local killerName = killerClone.Name
	local killerTime = killerClone:GetAttribute("Time") or 30 -- Default time if not set
	local killerPoints = killerClone:GetAttribute("Points") or 10 -- Default points if not set
	local killerDifficulty = killerClone:GetAttribute("Difficulty") or 0

	updateTimerEvent:FireAllClients(killerName, killerTime)
	updateDifficulty:FireAllClients(killerDifficulty)

	task.wait(killerTime)
	rewardSurvivors(killerPoints)
	warn("Rewarded!")
	killerClone:Destroy()
end

local function startCountdown()
	local music
	if IntermissionMusicEnabled then
		music=Instance.new("Sound",script)
		music.SoundId = "rbxassetid://"..IntermissionMusicList[math.random(1,#IntermissionMusicList)]
		music.Volume = 0.5
		music.PlaybackSpeed = 0
		music:Play()
		local t = tweenService:Create(music, TweenInfo.new(DelayToStopTheIntermissionMusic),{PlaybackSpeed = 1})
		t:Play()
	end
	for i = countdownTime, 0, -1 do
		updateCountdownEvent:FireAllClients(i)
		task.wait(1)
	end
	if IntermissionMusicEnabled then
		local t = tweenService:Create(music, TweenInfo.new(DelayToStopTheIntermissionMusic),{PlaybackSpeed = 0})
		t:Play()
		t.Completed:Connect(function()
			music:Destroy()
		end)
	end
	
	spawnRandomKiller()
	
	for _, player in Players:GetPlayers() do
		if player and player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
			local Humanoid = player.Character:FindFirstChildOfClass("Humanoid")
			if Humanoid.Health > 0 then
				table.insert(TableName, player)
				Humanoid.Died:Connect(function()
					if table.find(TableName, player) then
						for i, v in pairs(TableName) do
							if v == player then
								table.remove(TableName, i)
							end
						end
					end
				end)
			end
		end
	end
end

while true do
	TableName = {}
	startCountdown()
end


I am a novice developer and programmer, therefore I am not strong in Luau and therefore the solution may be simple, but I just can't find it.

The problem might be a typo, have you tried printing stuff or setting up breakpoints to see what’s the part that is breaking?

Yes, I tried to make breakpoints and added warn(“”) (Also with the rewardSurvivors function it was written in the Output TableName, it looked like this: “{}”. The script has not broken yet and it is fully functional until all these commands (warn, print, error) work.

also this part works correctly:

I believe the issue lies in your rewardSurvivors function,

local function rewardSurvivors(points)
	print(TableName)
	for _, player in TableName do
		local Players = game:GetService("Players")
		if Players:FindFirstChild(player.Name) then
			if player and player.Character and player.Character:FindFirstChildOfClass("Humanoid") then 
				local leaderstats = player:FindFirstChild("leaderstats")
				if leaderstats then
					local survivals = leaderstats:FindFirstChild("Survivals")
					local playerPoints = leaderstats:FindFirstChild("Points")
					if survivals and playerPoints then
						survivals.Value = survivals.Value + 1
						playerPoints.Value = playerPoints.Value + points
					end
				end
			end
		end
	end
end

try replacing it with this

Not working.

I also forgot to say that the boss disappears before the end of his timer, for example:

The boss appears for 60 seconds, when 55-59 seconds pass, the boss simply disappears (is deleted) and does not give rewards to the players. I.e. the boss disappears (is deleted) before the timer for some reason.


Also here is leaderstats script (ServerScriptService):

Leaderstats
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local survivals = Instance.new("IntValue")
    survivals.Name = "Survivals"
    survivals.Value = 0
    survivals.Parent = leaderstats

	local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Value = 0
    points.Parent = leaderstats
end)

Ok so after around 5 minutes I found the issue

Issue:

  • Exisiting players only got added to the table after the round had already ended
    (spawnRandomKiller() → Boss spawns → Wait time/round duration → rewardSurvivors(killerPoints) → Add players to the table → Empty table when the round ends

How to fix:

  • The section where you loop through all players and add them to a table for rewarding, that part, move it to the spawnRandomKiller() function, right above task.wait(killerTime)
local function spawnRandomKiller()
	local killers = killersFolder:GetChildren()
	if #killers == 0 then return end

	local randomKiller = killers[math.random(1, #killers)]
	local killerClone = randomKiller:Clone()
	killerClone.Parent = workspace

	local killerName = killerClone.Name
	local killerTime = killerClone:GetAttribute("Time") or 30 -- Default time if not set
	local killerPoints = killerClone:GetAttribute("Points") or 10 -- Default points if not set
	local killerDifficulty = killerClone:GetAttribute("Difficulty") or 0

	updateTimerEvent:FireAllClients(killerName, killerTime)
	updateDifficulty:FireAllClients(killerDifficulty)
	
	for _, player in Players:GetPlayers() do
		if player and player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
			local Humanoid = player.Character:FindFirstChildOfClass("Humanoid")
			if Humanoid.Health > 0 then
				table.insert(TableName, player)
				Humanoid.Died:Connect(function()
					if table.find(TableName, player) then
						for i, v in pairs(TableName) do
							if v == player then
								table.remove(TableName, i)
							end
						end
					end
				end)
			end
		end
	end

	task.wait(killerTime)
	rewardSurvivors(killerPoints)
	warn("Rewarded!")
	killerClone:Destroy()
end
1 Like

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