Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Could someone alter this script so that it uses the default KOs and WOs?

This script is from the Roblox Default Template 'FFA/Team Arena'. Could someone alter it so that it uses the default KOs and WOs instead of using a newly created model called KO - WO - A. This would be really appreciated! Also Configurations.GRANT_ASSISTS is false so don't worry about that. I have spent around 5 hours trying to find a way to make it run on KOs and WOs but was as you can see futile. Thanks for your time.

local PlayerManager = {}

-- ROBLOX Services
local Players = game.Players
local PointsService = game:GetService("PointsService")

-- Game Services
local Configurations = require(game.ServerStorage.Configurations)
local Events = game.ReplicatedStorage.Events
local ResetMouseIcon = Events.ResetMouseIcon
local TeamManager = require(script.Parent.TeamManager)
local DisplayManager = require(script.Parent.DisplayManager)

-- Local Variables
local PlayersCanSpawn = false
local GameRunning = false
local HitArray = { }
local ScoreArray = { }

-- Local Functions
local function OnPlayerAdded(player)
	-- Setup leaderboard stats
	local leaderstats = Instance.new("Model", player)
	leaderstats.Name = "leaderstats"
	
	local KWA = Instance.new("StringValue", leaderstats)
	if Configurations.GRANT_ASSISTS then
		KWA.Name = "KO - WO - A"
		KWA.Value = "0 - 0 - 0"
	else
		KWA.Name = "KO - WO"
		KWA.Value = "0 - 0"
	end
	
	ScoreArray[player] = { 0, 0, 0 } -- KOs, WOs, Assists
	
	TeamManager:AssignPlayerToTeam(player)
	
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			PlayerManager:PlayerDied(player)
			wait(Configurations.RESPAWN_TIME)
			if GameRunning then
				player:LoadCharacter()
			end
		end)
	end)
	
	if PlayersCanSpawn then
		player:LoadCharacter()
	else
		DisplayManager:StartIntermission(player)
	end
end

local function OnPlayerRemoving(player)
	TeamManager:RemovePlayer(player)
end

local function UpdatePlayerScore(player)
	local KOString = tostring(ScoreArray[player][1])
	local WOString = tostring(ScoreArray[player][2])
	local AssistString = tostring(ScoreArray[player][3])
	
	if not Configurations.GRANT_ASSISTS then
		if KOString:len() < WOString:len() then
			while KOString:len() < WOString:len() do
				KOString = " " .. KOString
			end
		else
			while WOString:len() < WOString:len() do
				WOString = WOString .. " "
			end
		end
		player.leaderstats["KO - WO"].Value = KOString .. " - " .. WOString
	else
		player.leaderstats["KO - WO - A"].Value = KOString .. " - " .. WOString .. " - " .. AssistString
	end
end

-- Functions
function PlayerManager:SetGameRunning(running)
	GameRunning = running
end

function PlayerManager:AllowPlayerSpawn(allow)
	PlayersCanSpawn = allow
end

function PlayerManager:ClearPlayerScores()
	for _, player in ipairs(Players:GetPlayers()) do
		local leaderstats = player:FindFirstChild("leaderstats")
		if leaderstats then
			local KWA
			if Configurations.GRANT_ASSISTS then
				KWA = leaderstats:FindFirstChild("KO - WO - A")
				if KWA then
					KWA.Value = "0 - 0 - 0"
				end
			else
				KWA = leaderstats:FindFirstChild("KO - WO")
				if KWA then
					KWA.Value = "0 - 0"
				end
			end
		end
	end
end

function PlayerManager:LoadPlayers()
	for _, player in pairs(Players:GetPlayers()) do
		player:LoadCharacter()
	end
end

function PlayerManager:DestroyPlayers()
	for _, player in pairs(Players:GetPlayers()) do
		player.Character:Destroy()
		for _, item in pairs(player.Backpack:GetChildren()) do
			item:Destroy()
		end
	end
	ResetMouseIcon:FireAllClients()
end

function PlayerManager:PlayerHit(hitPlayer, hittingPlayer)
	if hitPlayer == hittingPlayer then
		return
	end
	
	if not HitArray[hitPlayer] then
		HitArray[hitPlayer] = { }
	end
	
	for i = 1, #HitArray[hitPlayer] do
		if HitArray[hitPlayer][i]== hittingPlayer then
			return
		end
	end
	table.insert(HitArray[hitPlayer], hittingPlayer)
end

function PlayerManager:PlayerDied(player)
	if HitArray[player] then
		for i = #HitArray[player], 1, -1 do
			local hittingPlayer = HitArray[player][i]
			if hittingPlayer ~= player then
				if i == #HitArray[player] then
					ScoreArray[hittingPlayer][1] = ScoreArray[hittingPlayer][1] + 1
					TeamManager:AddTeamScore(hittingPlayer.TeamColor, 1)
					spawn(function() pcall(function() PointsService:AwardPoints(hittingPlayer.userId, Configurations.PLAYER_POINTS_PER_KO) end) end)
				else
					ScoreArray[hittingPlayer][3] = ScoreArray[hittingPlayer][3] + 1
					spawn(function() pcall(function() PointsService:AwardPoints(hittingPlayer.userId, Configurations.PLAYER_POINTS_PER_ASSIST) end) end)
				end
				UpdatePlayerScore(hittingPlayer)
			end
		end
	end
	
	ScoreArray[player][2] = ScoreArray[player][2] + 1
	HitArray[player] = nil
	UpdatePlayerScore(player)
end

-- Event Bindings
Players.PlayerAdded:connect(OnPlayerAdded)
Players.PlayerRemoving:connect(OnPlayerRemoving)

return PlayerManager

1 answer

✓ Accepted answer

I wrote the below based on your previous question, but it had been deleted when I went to post. It looks like you are wanting to change the default template system now instead of working with it as I had assumed from your original post. As such the below code might not suit your needs anymore, but I will post it for you in any case. I can have another look at it tomorrow if what I have here doesn't suit your needs (I'm about to head to bed).

Everything below is what I would have posted to your old thread.


Change the script you have in your NPC's to this:

local PlayerManager = require(game.ServerScriptService.MainGameScript.GameManager.PlayerManager)
local Humanoid = game.Workspace.Squad1.Grunt1.Humanoid

function PwntX_X() 
	local tag = Humanoid:findFirstChild("creator") 
	if tag ~= nil then 
		if tag.Value ~= nil then 
			 PlayerManager:PlayerKilledNPC(tag.Value)
		end 
	end 
end 

Humanoid.Died:connect(PwntX_X)

And add this function in PlayerManager at the bottom, below the PlayerManager:PlayerDied function and above -- Event Bindings

function PlayerManager:PlayerKilledNPC(player)
	ScoreArray[player][1] = ScoreArray[player][1] + 1
	TeamManager:AddTeamScore(player.TeamColor, 1)
	UpdatePlayerScore(player)
end

Assuming the weapons you are using add the creator tag to the NPC's (at a glance it doesn't look like the template rocket launcher does), then these two changes will award a point to a player for killing an NPC.

1 comment

0

thx sooo much bro! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.