Script isn't working properly

Hello,
I’ve been working on my game and recently, after I updated the Auras/Effects script to make it easier on myself later on, it stopped working.

I also tried a few methods to fix this issue such as Debugging, researching on the Forums and Reddit, alternative sites, and so forth. But these did not fix the issue.

It’s been happening for a couple weeks, players are now complaining why the game isn’t working and it’s really getting annoying trying to fix. Assuming it might have to do with the phasesTable or trying to call the function.

-Server

-- @Zorgoths/Zoneriuz on RBLX (TKE: PhaseScript)
local Players = game:GetService("Players")
local RPS = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
local BadgeSer = game:GetService("BadgeService")
local TweenSer = game:GetService("TweenService")
local Debris = game:GetService("Debris")

local AuraMod = require(RPS.Modules:FindFirstChild("ChangeAuraMod"))
local Container = script:FindFirstChild("CONTAINER")
local ConnectonsModule = require(Container:FindFirstChild("DeathConnectionsMod"))

local PhaseEvent = RPS.Events.GloveRemotes:FindFirstChild("KSPhaseEvent")
local SongCreditEvent = RPS.Events.Remotes:FindFirstChild("MusicCreditEvent")

local function copySound(sound, soundToCopy)
	if not sound or not soundToCopy then return end
	for _, property in pairs({"SoundId", "SoundGroup", "RollOffMaxDistance", "RollOffMinDistance",
		"Volume", "PlaybackSpeed", "TimePosition", "Playing", 
		"Looped", "MaxDistance", "EmitterSize"}) do
		pcall(function()
			sound[property] = soundToCopy[property]
		end)
	end
end

local function findDummy(childName)
	local Folder = RPS.Assets.GloveAssets.Killstreak
	for _, child in pairs(Folder:GetChildren()) do
		if child:IsA("Model") and child.Name == childName and child:FindFirstChildOfClass("Humanoid") then
			return child
		end
	end
end

local function changeOverhead(char, name)
	local overhead = char.Head.Overhead.Label
	for _, child in pairs(overhead:GetChildren()) do
		if child:IsA("UIGradient") and child.Name == name then
			child.Enabled = true
		elseif child:IsA("UIGradient") and child.Name ~= name then
			child.Enabled = false
		end
	end
end

local function getPlrChar(player)
	if player then
		return player.Character or player.CharacterAdded:Wait()
	end
end

local function creditSong(char)
	local player = Players:GetPlayerFromCharacter(char) or warn("no player found", char.Name)
	local HRP = char.PrimaryPart or char:FindFirstChild("HumanoidRootPart") or warn(player.Name.." does not have a HumanoidRootPart!", script.Name)
	
	local song = HRP:FindFirstChildOfClass("Sound")
	if song and song:GetAttribute("KSAURA") then
		local author = song.Author or "Unknown"
		local name = song.Song or "Unknown"
		SongCreditEvent:FireClient(player, author, name)
	end
end

local phasesTable = {
	{name = "LilFire", kills = 1, nextKills = 2},
	{name = "BigFire", kills = 2, nextKills = 3},
	{name = "StrongFire", kills = 3, nextKills = 4},
	
	{name = "P1", kills = 4, nextKills = 5},
	{name = "P1_2", kills = 5, nextKills = 6},
	{name = "P1_3", kills = 6, nextKills = 8},
	{name = "P1_4", kills = 8, nextKills = 10},
	
	{name = "P2", kills = 10, nextKills = 25},
	{name = "P3", kills = 25, nextKills = 50},
	{name = "P4", kills = 50, nextKills = 75},
	{name = "P5", kills = 75, nextKills = 100},
	{name = "P6", kills = 100, nextKills = 150},
	{name = "P7", kills = 150, nextKills = 250},
	{name = "P8", kills = 250, nextKills = 350},
	{name = "P9", kills = 350, nextKills = 425},
	{name = "P10", kills = 425, nextKills = 500},
	{name = "P11", kills = 666, nextKills = 777},
	{name = "P12", kills = 777, nextKills = 850},
	{name = "P13", kills = 850, nextKills = 935},
	{name = "P14", kills = 935, nextKills = 1000},
	{name = "P15", kills = 1000, nextKills = 1001},
}

local function getPhase(kills)
	for _, phase in ipairs(phasesTable) do
		if kills >= phase.kills and kills < phase.nextKills then
			return phase
		end
	end
	
	wait(0.5)
	warn("NO PHASE FOUND FOR KILLS: ", kills)
	return {name = "P1", kills = 0, nextKills = 1}
end

local function handlePhase(char, phase)
	if not phase then warn("NO PHASE FOUND!") return end
	
	local Player = Players:GetPlayerFromCharacter(char) or Players:FindFirstChild(char.Name)
	local Char = getPlrChar(Player)
	if not Char then
		error("script errored to get character for player: ", Player.Name)
		return
	end
	local Overhead = Char.Head:FindFirstChild("Overhead").Label

	local Hum = Char:FindFirstChildOfClass("Humanoid")
	local HRP = Char:FindFirstChild("HumanoidRootPart") or warn("No HumanoidRootPart", Player.Name)

	local Killstreak = Char:FindFirstChild("Killstreak") or (Player.Backpack and Player.Backpack:FindFirstChild("Killstreak"))
	local Glove = Killstreak.Glove
	local Hitbox = Killstreak.GloveHitbox

	local SlapSFX = Glove.SlapSFX
	local PowerVal = Killstreak.Scripts.SlapHandler.Configuration.Power.Value
	local GloveSpeed = Killstreak.Scripts.SlapHandler.Configuration.Timer.Value
	ConnectonsModule.CleanupEffects(Player)
	
	--[PHASES]--
	if phase.Name == "LilFire" then
		Glove.Oldfire.Rate = 2.35
	elseif phase.Name == "BigFire" then
		Glove.Oldfire.Rate = 4
		PowerVal = 38
                -- rest of the other phases here, yada yada ditto.
	end
end

local function onBindEventFired(char, kills)
	local player = Players:GetPlayerFromCharacter(char)
	if not player then warn("player not found for char", char.Name) return end
	
	local currentPhase = getPhase(kills)
	handlePhase(char, currentPhase)
end

PhaseEvent.Event:Connect(onBindEventFired)

-Module (Using ProcessReceipt module since the ToolsModule is too long)

local functionsModule = {}

local Players = game:GetService("Players")
local RPS = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")

local Events = RPS:WaitForChild("Events")
local Modules = RPS:WaitForChild("Modules")

local PassCheckModule = require(Modules:WaitForChild("GamepassOwnershipModule"))

function functionsModule:onKillsPurchased(player)
	wait(1.5)
	if not player then return false end
	local character = player.Character or player.CharacterAdded:Wait()
	if not character then return false end

	local backpack = player:FindFirstChildOfClass("Backpack")
	local tool = character:FindFirstChild("Killstreak") or (backpack and backpack:FindFirstChild("Killstreak"))
	if not tool then
		warn("Killstreak tool not found for player:", player.Name)
		return false
	end

	local killsValue = tool:FindFirstChild("Config") and tool.Config:FindFirstChild("KillsVal")
	if not killsValue then
		warn("KillsValue not found in tool configuration for player:", player.Name)
		return false
	end

	local vfxEvent = RPS.Events.GloveRemotes:FindFirstChild("KillstreakVFXEvent")
	local phaseEvent = RPS.Events.GloveRemotes:FindFirstChild("KSPhaseEvent")
	local textEvent = RPS.Events.GloveRemotes:FindFirstChild("KSTextUpdEvent")

	local totalKills = player.leaderstats and player.leaderstats:FindFirstChild("Total Kills")
	local monthlyKills = player.leaderstats and player.leaderstats:FindFirstChild("Monthly Kills")

	if not totalKills or not monthlyKills then
		warn("Leaderstats not properly set up for player:", player.Name)
		return false
	end

	local normAmt = 10
	local passAmt = 20 / 1.5
	local addAmount = PassCheckModule.CheckPassOwnership(player, 911579621) and passAmt or normAmt

	for i = 1, addAmount do
		killsValue.Value += 1
		if character:FindFirstChild("Head") and character.Head:FindFirstChild("Overhead") then
			character.Head.Overhead.Label.Text = tostring(killsValue.Value)
		end

		if phaseEvent then phaseEvent:Fire(character, killsValue.Value) end
		if vfxEvent then vfxEvent:FireClient(player) end
		if textEvent then textEvent:FireClient(player, killsValue.Value) end

		wait(0.075)
	end

	return true
end

return FunctionsModule

You haven’t said what isn’t working

1 Like

Ah, sorry, was in a rush to fix this issue so I could get off Studio for the day.
The issue for the script is that the getPhase and handlePhase functions aren’t working correctly.

No errors, warnings, or prints have been found inside the script which is odd since Roblox would usually create a new error into the output explaining what went wrong, which it didn’t this time.

I’m assuming it might be a problem with the phasesTable but I can’t be completely 100% sure on this.

1 Like

It could be that one of the required modules is yielding indefinitely. I do see an additional bug with you mistaking the following code for creating references to the “Value” property:

local PowerVal = Killstreak.Scripts.SlapHandler.Configuration.Power.Value
local GloveSpeed = Killstreak.Scripts.SlapHandler.Configuration.Timer.Value

This stores the current state. It doesn’t create a shortcut to the property; each time you want to read or write to a value instance, you must access its “Value” property directly

1 Like

So about this,
I removed these values a couple days ago to see if this was the issue, to which it wasn’t. Afterwards, I assumed this wasn’t a problem so I added it back to the script.

Thanks for noticing this, but it isn’t my initial problem with the script and the script doesn’t print any errors or warnings to the console. The print statements are called upon before the script defines these values, rendering this as not a solution.

1 Like

I am aware that this isn’t the problem. I am simply pointing out an additional issue. Did you investigate the potentiality of your modules yielding indefinitely? Place a breakpoint before you begin defining your functions. If it does not trigger, then this is your problem

1 Like

Fixed the issue after a lot of attempts. Apparently, the lua phase.Name statement was supposed to be lua phase.name.

Only issue now is that the script keeps giving phases after unlocking the requirement, though I’ll fix this aswell.

1 Like

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