Local Script possibly stopping my combat continuing

-- \\ Player-Related Variables //--

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HUM = Character:WaitForChild("Humanoid")
local Humrp = Character:WaitForChild("HumanoidRootPart")

-- \\ Get-Service Variables // -- 

local UIS = game:GetService("UserInputService")

local RS = game:GetService("ReplicatedFirst")

-- \\ Server-Script-Variables // --

local SSS = game:GetService("ServerScriptService")

local RS = game:GetService("ReplicatedStorage")

local RunS = game:GetService("RunService")

local SP = game:GetService("StarterPack")

local Combat101 = SSS:FindFirstChild("CombatHandler")

local CAS = game:GetService("ContextActionService")

--local CM = require(RS.CheckHumanoid)



-- \\ Cooldowns // --

local Debounce = false


local CDS = {

	1,
	2

}

local CurrTime = 0

local PrevTime = 0

local HoldingTool = false

-- \\ Misc. Variables // --

local Count = 0

local AirKickEnabled = false

local AerialDebounce = false

-- \\ Functions // --
function Grippy()
	Character.ChildAdded:Connect(function(NewChild)
		if NewChild:IsA("Tool") then
			HoldingTool = true

		end
	end)
end

function unGrippy()
	Character.ChildRemoved:Connect(function(RemovedChild)
		if RemovedChild:IsA("Tool") then
			HoldingTool = false
		end
	end)
end

--[[HUM.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		if not AirKickEnabled and AerialDebounce then
			wait(.02)
			if HUM:GetState() == Enum.HumanoidStateType.Freefall then

				AirKickEnabled = true 
				AerialDebounce = true
				task.wait(15)
				AirKickEnabled = false
				AerialDebounce = false
			elseif HUM:GetState() == Enum.HumanoidStateType.Landed then
				AirKickEnabled = false
				task.wait(30)


			end
		end
	end
end)]]


UIS.InputBegan:Connect(function(Input, Processed)
	Grippy()
	if Processed then
		return
	elseif Input.UserInputType == Enum.UserInputType.MouseButton1 and not UIS:IsKeyDown(Enum.KeyCode.F) then
		if HoldingTool == true then
			return
		elseif HoldingTool == false then
			if Debounce == false then
				Debounce = true 
				CurrTime = os.clock()


				local PT = CurrTime - PrevTime
				if PT < 1 then
					Count += 1
					if Count > 4 then
						print("Resetting Combo.")
						Count = 1
					end
				else
					Count = 1
				end
				print("Ugh?")
				RS.CombatEvents.Combat:FireServer(Count)
				print("Are we working")
				unGrippy()
			end
		end
	end
end)

RS.CombatEvents.Combat.OnClientEvent:Connect(function(bool)	
	PrevTime = CurrTime

	if bool then 
		wait(CDS[2])
		Debounce = false
	else
		Debounce = false
	end
end)

RS.Visuals.SlightSS.OnClientEvent:Connect(function(Count)
	local Hum = Player.Character:WaitForChild("Humanoid")
	if Count == 4 then
		for i = 1, 12 do
			local x = math.random(-20,20)/100
			local y = math.random(-20,20)/100
			local z = math.random(-20,20)/100

			Hum.CameraOffset = Vector3.new(x,y,z)
			wait()
		end
		Hum.CameraOffset = Vector3.new(0,0,0)
	else
		for i = 1, 5 do
			local x = math.random(-15,15)/100
			local y = math.random(-15,15)/100
			local z = math.random(-15,15)/100

			Hum.CameraOffset = Vector3.new(x,y,z)
			wait()
		end

		Hum.CameraOffset = Vector3.new(0,0,0)
	end
end)

I’m dealing with two issues in this script, but I just want to directly go for the one that I’m dealing with is my combat completely just breaking after making an attempt to try and attack once stunned, and I’ll just have the inability to continue attacking.

This is the result of trying to attack after the stun was active and now isn’t. I checked out the server script, and it seemed decent, so when I looked at the local script, it seemed to have stopped printing all of sudden, so that’s why this second post is being made

Also in hopes that I can fix the tool issue because the method I’m using is giving me quite the issue in itself.

Alright, remove all return instances from your script in the server.

As with the client script, UserInputService:IsKeyDown() might cause issues. I debug the if statements first, like elseif HoldingTool == false, which is most likely your issue. Try debugging this and see if it fixes the problem. If so, send a reply and tell us what you did.

I’m assuming my if not Stunned statement worked in my stead, I stopped all of the return ends as well btw, but I decided to turn off my HoldingTool statement, and the combat would still work, the only thing was the count would increase if I tried attacking whilst stunned. On top of this, now a new issue occurs that if I decide to pick a tool, the combat would play (I made the Grippy/UnGrippy functions in a chance to fix this since I know no other method), but I don’t know how to fix it (Maybe CAS/ContextActionService).

I never liked ContextActionService, but I like the system you got here. I did make a “universal system” for vehicles with ContextActionService, but I made a newer version to that using UserInputService because binding and unbinding was a hassle to do and didn’t work sometimes.

To do deeper debugging, try printing the value of HoldingTool, and possibly add multiple values for different outcomes (1 is retry, 2 is okay) or something like that, to automatically fix the problem.

HoldingTool seems to work properly, the only bug I ever had with it is that if I decided to pick a tool before hitting the air the combat would be unaccesiable, but it seems to stay false otherwise. So, now I’m a little bit confused, but one by one I’ll be bringing back the return if statements.

Now that I look at the script again, I don’t see debounce ever going back to false…
Is this finally the solution?

Alas, no

I handle that after the Count variable hits 4 in the server, so it does go back. If that was the case that would’ve been amazing. On that note, I decided to remove the comment off in the server on everything besides return “Stun”, so I’m just sitting here wondering if that really is the issue, and if it is, how am I meant to fix it?

Nevermind,

I just tried to attack once I was blocking and the local script seems to be giving me a red flag, telling me it’s a no go after

Which is leading me to wonder if the issue is either Debounce, or HoldingTool, since I put a print statement in between these two

Seems odd to be handling that in the server. I would print out messages to see if the event is actually sending/receiving messages from/to the client/server.

I also want you to double check if the server and client are receiving and sending messages through the same event, and if that’s causing a conflict.

Reply to edited reply:

I believe it is either that or the RemoteEvent you’re using. If you are sending information to the server to receive it again, use a RemoteFunction instead.

So there seems to be a conflict, reason I say this? It’s cause once I try to attack during blocking, it stops printing anything past the debounce part. So, now I’m trying to think about how I would solve an issue like this, because nothing is really popping up in my mind at the moment. Either a rework of how the debounce works, or something else, but I think a server debounce might be the way to go.

Sending that same bool value to the server? Nah. Moving on.

To fix the issue I would make Debounce a number instead of a boolean, and when Debounce is 1 it means it’s debounce, and when Debounce is 2 it means that HoldingTool is active. You can make that logical statement by saying if Debounce >= 1, and making Debounce 0 would disable it. It might take more programming but I’ve found it to be a reasonable method for something like this.

If you have a possible code example, or devforum link I’d appericate if I could see it. I can’t really picture it completely in my mind, only in fragments on how that would look like typed out.

Alright, let’s say we have a “Module loader”, which handles the results of the modules.

It would look like BaseAdmin’s Features loader, except with numbers instead of stuff like “Retry” and “Cancel”. It will also have operators to choose if it can retry and cancel. I revamped the script to look more like what I’m talking about.

local module = {}

module.features = script.Parent.FeatureModules


--auto function used for about anything

module.auto = function(Msg, Hint, featureSettingTable, output)
	if output then
		print("FEATURE OUTPUT DEBUG MODE")
	end
	for _, feature in pairs(module.features:GetChildren()) do
		local fconf = featureSettingTable[feature.Name]
		local active = Instance.new("StringValue")
		active.Name = "Active"
		active.Value = "Disabled"
		active.Parent = feature
		if fconf and fconf.Enabled then
			local function addFeature()
				if output then
					print("LOADING FEATURE: ", feature.Name)
				end
				local retry
				retry = function()
					active.Value = "Running"
					local status, s, e = require(feature)(fconf)
					active.Value = status or "Loaded"
					if status > 1 then
						Hint(feature.Name.." failed to initialize! Retrying shortly. Please check the feature settings. Error details:\n\n<font color=\"rgb(255,0,0)\">"..e.."</font>")
						wait(fconf.RetryDelay or 5)
						retry()
					elseif status > 2 then
						delay(5, function()
							Msg(feature.Name.." aborted because "..((s == false and "an error occurred. Error details:\n\n"..e) or (typeof(s)=="string" and ":\n\n"..s) or (not s and ": no reason given. This may be an unknown error or does not have a message assigned to it. Argument 3:\n\n"..e)), 20)
						end)
					end
				end
				retry()
			end
			if fconf.Instant then
				addFeature()
			else
				spawn(addFeature)
			end
		end
	end
end

return module

[spoiler]
putting this in BaseAdmin might result in features failing to retry. Don't actually use it in BaseAdmin.
[/spoiler]

Gonna need to look over this over night, but what I’m generally getting from this that the status just means a certain state that the specific part of the script is in?

Well, yeah. Alright, another example. Let’s say we have exactly what you have.

if mode == 0 then print("do stuff and return") return
else
if mode >= 1 then
print("Debounce, and HoldingTool")
return
elseif mode >=2 then
print("Debounce, and NOT HoldingTool")
return
end

I hope this makes sense and is understandable. I bet and hope the script will not use return statements, but this is a script using return statements, since it is easier to demonstrate.

1 Like

Is there a possible way to consistently check if one value is true and the other isn’t so that mode’s number val can change?

I recommend just making them work without some loop like that. I would make something like if mode == 1 then mode == 2 end in the HoldingTool section. Of course, I would add else statements and stuff like that.

So, would you believe something like this would be good, being ran at the start of the script?

local function modeCheck()
	if HoldingTool == true and Debounce == true then
		Mode = 2
		
	else
		if HoldingTool == false and Debounce == true then
			Mode = 1
		elseif HoldingTool == false and Debounce == false then
			Mode = 0
			
			
		end
	end
end

Yep. But instead of setting Mode I would rather return a value, whether it should run or not, with logic. But I think that you should figure out why HoldingTool is failing when Debounce is on (assuming that’s what’s happening).

Well, once I start pressing, the issue seems to be that the game is still making the Debounce true, because I have no returns for “if character attribute is blocking == true then return” or something of that sort, it’ll fire the local. So, now I feel like if I add that I make the issue significantly easier and possibly don’t have to get as indepth as I though I did (of course this is coding we are talking about it’s just really just a lot of testing and hoping it works.)

Yeah. You can also do something like if Debounce == true and HoldingTool == false then HoldingTool = true end, to fix the problem, if you know both values should not be true at the same time.

But most likely that’s not the case with these values.

And that’s the part where I know I cannot solve the problem… for now.