Function still detects condition as false even though it is true

I’m trying to create a parrying system where if the player presses “F,” they will block any attack for a short amount of time. To do this, I created a module script that manages status effects and I added a “parrying” effect through the parry script. I have confirmed that the player does have the effect through another server script, but the 3rd script below somehow detects that the player doesn’t and the damage goes through. (FYI I’m new to scripting.)

Here’s the module script that checks if the player has a specific effect (sem stands for StatusEffectsManager and se stands for StatusEffects):

	if se[player] == effectName then
		return true
	else
		return false

Here’s the script that tests whether or not the player has the “parrying” effect (it shows a true output):


game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		
		while true do
			print(sem.CheckStatusEffect(plr, "parrying"))
			task.wait(1)
		end
		
	end)
end)

And here’s the script that detects that the player somehow doesn’t have the effect:

			if touched.Parent ~= plr.Character and touched.Parent:FindFirstChild("Humanoid") then
				local ehum = touched.Parent.Humanoid

				if hitdebounce then return end

				if sem.CheckStatusEffect(touched.Parent, "parrying") then
					ehum:TakeDamage(0)
				else
					ehum:TakeDamage(damage)
					print(touched.Parent, sem.CheckStatusEffect(touched.Parent, "parrying"))
				end

				hitdebounce = true
			end

its likely because you are not relaying the change to the server, though I am just making a guess based on context:

you use a module script, and likely on client, you set the se of a player from a local script == parrying for example

then in a serverscript you fetch from the same module, however of course based on client/server architecture, any se of a player will be false when you try to check due to not letting the server know

remember a you cannot do this: local script ->modulescript<-/x/->server. inherently you have to use the proper communication channels to achieve this effect.

do let me know if this isnt the case though and that you are using remote events or equivalent.

Thanks, but for the parrying effect, it is added from a server script through this line of code:

sem.AddStatusEffect(plr, "parrying")

and here’s the part of the module script that controls the adding of effects:

function sem.AddStatusEffect(player, effectName)
	se[player] = effectName
end

its likely this then

you add to the se table the player object i believe.

touched.Parent is the character.

--Do 
game.Players:GetPlayerFromCharacter(touched.Parent)

if thats not it then thats all i can see.

so modify this line:

if sem.CheckStatusEffect(touched.Parent, "parrying") then

Thanks, it’s a lot better than asking ChatGPT 20 times for help.

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