Value inside morph refuses to deplete unless a useless variable is called in the FireServer for the Tool's Script

So I’m currently in the process of reworking almost every single Tool in the game for this fighting game that I am currently working on by replacing the scripts inside of them with Client scripts so the attacks will fire in their proper directions.

There is this one attack in particular that has been giving me a hard time, it’s an attack that can only be called if you have at least one kill, kills are stored as a value inside of the morph for this one specific character, once that attack gets used it will deplete that kill’s value inside of the morph.

Problem being though, whenever the kill variable in the Tool’s script gets called in the FireServer function in the Client script, the script inside of the ServerScriptService that responds to this call will not deplete the value. Strange thing being though, I have done this exact same thing literally yesterday with just about the same steps and everything and it worked without a hitch, but for whatever reason this specific instance refuses to cooperate.

Here is the script for the Tool in question:

local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Remote = game.ReplicatedStorage.FireAttack --The RemoveEvent that gets called to trigger the script inside of ServerScriptService

active = 1
ogName = script.Parent.Name

script.Parent.Activated:Connect(function()
	if active == 1 then
		active = 0
		if script.Parent.Parent.Chest.Middle.EXP.Disabled == true then --Will not activate if a certain other move is being used, but that isn't important to this post
			if script.Parent.Parent.kills.Value > 0 then --Activates when kills are above zero
				local Origin = Player.Character.HumanoidRootPart.Position
				local Direction = Camera.CFrame.LookVector
				local Owner = script.Parent.Parent
				local Folder = script.Parent.folder.Value
				local Attack = script.Parent.attack.Value
				local Killer = 1 --The amount of kills to be subtracted

				Remote:FireServer(Origin, Direction, Owner, Folder, Attack, Killer)
				local cd = script.Parent.cd.Value
				local origcd = cd
				for i = 1,cd do
					script.Parent.Name = cd/(script.Parent.division.Value)
					task.wait(1/(script.Parent.division.Value))
					cd-=1
				end
				cd = origcd
				script.Parent.Name = ogName
			else
				script.Parent.Name = "NOT A SINGLE SOUL."
				task.wait(0.5)
				script.Parent.Name = ogName
			end
		else
			script.Parent.Name = "PATIENCE."
			task.wait(0.5)
			script.Parent.Name = ogName
		end
		active = 1
	end
end)

And here is the code for the script inside of ServerScriptService:

local Remote = game.ReplicatedStorage.FireAttack

Remote.OnServerEvent:Connect(function(Player, Origin, Direction, Owner, Folder, Attack, DT, Killer)
	Direction = Vector3.new(Direction.X, 0, Direction.Z)
	if Direction.Magnitude == 0 then return end
	Direction = Direction.Unit

	local Bone = game.ServerStorage.attacks[Folder][Attack]:Clone()
	Bone.owner.Value = Owner
	if Bone:FindFirstChild("owner2") ~= nil then
		Bone.owner2.Value = Owner.Name
	end
	Bone.Parent = game.Workspace
	Bone.PrimaryPart = Bone.Head
	Bone:PivotTo(CFrame.lookAt(Origin, Origin + Direction))
	
	if Player.Character:FindFirstChild("kills") ~= nil then --The code in question
		if Player.Character.Cost.Value == 9666 then --Makes it so that only a specific character with that cost amount will be able to undergo this operation inside the script
			if Killer ~= nil then
				Player.Character.kills.Value -= Killer --This is the code that will not work
			end
		end
	end
	
	if Player.Character:FindFirstChild("dt") ~= nil then --And this is the code that works no problem despite having basically the same setup as the kills value thing, even right now as I am working on this code
		if Player.Character.Cost.Value == 1350 then
			if Player.Character.dt.Value ~= 100 then
				if Player.Character.dt.Value >= DT then
					Player.Character.dt.Value -= DT
				else
					Player.Character.dt.Value = 0
				end
			else
				Player.Character.dt.Value = 0
				Player.Character.Head.fire:Play()
			end
		end
	end
end)

Strangely, the code inside the tool will make the code for depleting the kills value inside the ServerScriptService script work if, and only if, it has some useless throwaway variable added to the FireServer function?

local funny = 1
Remote:FireServer(Origin, Direction, Owner, Folder, Attack, Killer)

I would have just done that and called it a day but I do feel like there has to be a better way to resolve this issue than that.

Essentially, I need to figure out why the code that is supposed to deplete the kills value inside of the morph whenever an attack that depletes kills is used isn’t depleting any kills. Any and all help will be greatly appreciated, thank you ! ^ ^

I figured it out, it was because of the order in which the Killer variable was being called in.
I figured this out when I switched Killer and DT around, that attack now worked but the other attacks that used the DT variable no longer worked.
So I removed the Killer variable and decided to have the part of the code that subtracts the kill value be DT instead as sort of like a stand-in for any miscellanous properties an attack may have.

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