SetAttribute not working inside of Module script

Whenever I get parried I cannot M1 because the swing and the attack aren’t set back false for some reason. I play this module script inside a module script and then to a server script. There aren’t any error messages inside of the output either.

-- Services 
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local SoundService = game:GetService("SoundService")
local Debris = game:GetService("Debris")

-- Folders 
local RSStorage = RS.Storage
local RSModule = RSStorage.Modules
local SSModule = SS.Modules
local Events = RSStorage.RemoteEvents
local WeaponSounds = SoundService.SFX.Weapons
local WeaponAnimsFolder = RSStorage.Animations.Weapons

-- Events
local VFXEvent = Events.VFX

-- SoundsModule
local SoundsModule = require(RSModule.Combat.SoundsModule)
local ServerCombatModule = require(SSModule.CombatModule)
local StunHandler = require(SSModule.MISC.StunHandlerV2)
local WeaponStats = require(SSModule.Weapons.WeaponStats)

-- Main Script



function module.BodyVelocity (parent, HRP, Knockback, stayTime)
	local bv = Instance.new ("BodyVelocity")

	bv.MaxForce = Vector3.new(math.huge,0,math.huge)
	bv.P = 50000
	bv.Velocity = HRP.CFrame.LookVector * Knockback
	bv.Parent = parent

	Debris:AddItem(bv,stayTime)
end

function module.Parrying(char, eChar, hitPos) -- echar is the one who we hit and the char is the one that attacked
	local currentWeapon = char:GetAttribute("CurrentWeapon")
	local eHRP = eChar.HumanoidRootPart
	local HRP = char.HumanoidRootPart
	
	
	local WeaponStat = WeaponStats.getStats(currentWeapon)
	local ParryPosture = WeaponStat.ParryDamage
	local knockback = WeaponStat.Knockback
	
	
	
	char:SetAttribute("Blocking", char:GetAttribute("Blocking") + ParryPosture) 
	eChar:SetAttribute("Blocking", eChar:GetAttribute("Blocking") - ParryPosture /2) 
	
	if eChar:GetAttribute("Blocking") <= 0 then eChar:SetAttribute("Blocking", 0) end
	
	if char:GetAttribute("Blocking") >= 100 then
		print ("Enemy Has Been Guardbroken")
		module.GuardBreak(char)
		return
	end
	
	VFXEvent:FireAllClients("CombatEffects", RSStorage.VFX.Combat.Parry, hitPos, 3)
	SoundsModule.PlaySound(WeaponSounds[eChar:GetAttribute("CurrentWeapon")].Blocking.Parry, eChar.Torso)
	
	
	ServerCombatModule.stopAnims(char.Humanoid)
	
	char.Humanoid.Animator:LoadAnimation(WeaponAnimsFolder(char:GetAttribute("CurrentWeapon")).Blocking.Parry):Play()
	
	StunHandler.Stun(char.Humanoid,.3,8,0)
	StunHandler.Stun(eChar.Humanoid,.15,8,0)
	module.BodyVelocity(HRP, HRP,-knockback, .2)
	
	
	module.BodyVelocity(eHRP, eHRP,knockback, .2)
	
	char:SetAttribute("Attacking", false)
	char:SetAttribute("Swing", false)
end
1 Like

did you set the attributes to true via a client sided script? That’s the only the only issue that i can think of while looking at this - the server can’t really interact with things that only the client has information on.

1 Like

No, I had it connected to a module then to a server script. I could send the scripts if you’d like.

Have you tried debugging by printing? See if the code fully executes. Is there a while loop that’s blocking some of the bottom parts of the script?

If all fails, then sure, I’ll be able to help you further if you sent me the scripts

You didn’t gave us much info about it but if the first "Blocking" attribute work fine then there’s obviously something that yield your code in-between, it could be one of these parts.

if char:GetAttribute("Blocking") >= 100 then
		print ("Enemy Has Been Guardbroken")
		module.GuardBreak(char)
		return
	end
SoundsModule.PlaySound(WeaponSounds[eChar:GetAttribute("CurrentWeapon")].Blocking.Parry, eChar.Torso)
ServerCombatModule.stopAnims(char.Humanoid)
char.Humanoid.Animator:LoadAnimation(WeaponAnimsFolder(char:GetAttribute("CurrentWeapon")).Blocking.Parry):Play()
StunHandler.Stun(char.Humanoid,.3,8,0)
StunHandler.Stun(eChar.Humanoid,.15,8,0)

This is the module script that I had linked to it.

local module = {}

-- Services 
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local StarterPlayer = game:GetService("StarterPlayer")
local SoundService = game:GetService("SoundService")
local Debris = game:GetService("Debris")

-- Folders 
local WeaponsSounds = SoundService.SFX.Weapons
local RSStorage = RS.Storage
local RSModules = RSStorage.Modules
local SSModules = SS.Modules 
local Events = RSStorage.RemoteEvents

-- Events
local CombatEvent = Events.Combat
local VFX_Event = Events.VFX


-- Modules 
local SoundsModule = require(RSModules.Combat.SoundsModule)
local ServerCombatModule = require(SSModules.CombatModule)
local WeaponStats = require(SSModules.Weapons.WeaponStats)
local HelpfulModule = require(SSModules.MISC.Helpful)
local StunHandlerV2 = require (SS.Modules.MISC.StunHandlerV2)

function module.BodyVelocity (parent, HRP, Knockback, stayTime)
	local bv = Instance.new ("BodyVelocity")
	
	bv.MaxForce = Vector3.new(math.huge,0,math.huge)
	bv.P = 50000
	bv.Velocity = HRP.CFrame.LookVector * Knockback
	bv.Parent = parent
		
	Debris:AddItem(bv,stayTime)
end


function module.Normal_HitboxHit(plr,char,weapon,Hitbox,...)
	local HitAnim = ...
	Hitbox.OnHit:Connect(function(hit,eHum)
		if eHum and eHum.Parent ~= char then
			local eChar = eHum.Parent
			local eHRP = eChar.HumanoidRootPart
			
			
			
			if eHum.Health > 0  and not eChar:GetAttribute("Iframes") then 
				local WeaponStat = WeaponStats.getStats(weapon)
				local damage = WeaponStat.Damage
				local knockback = WeaponStat.Knockback
				local RagdollTime = WeaponStat.RagdollTime
				local stunTime = WeaponStat.StunTime
				
				if HelpfulModule.CheckForStatus(eChar,char,damage,hit.CFrame, true,true) then return end
				
				eHum:TakeDamage(damage) 
				
				
				ServerCombatModule.stopAnims(eHum)
				
				VFX_Event:FireAllClients("CombatEffects", RSStorage.VFX.Combat.Blood, hit.CFrame, 3)
				
				-- Highlight
				VFX_Event:FireAllClients("Highlight", char and eChar,.5,Color3.fromRGB(170, 0, 0), Color3.fromRGB(255, 255, 255))
				VFX_Event:FireAllClients("Highlight", char,.5,Color3.fromRGB(255, 255, 255), Color3.fromRGB(0, 0, 0))

				SoundsModule.PlaySound(WeaponsSounds[weapon].Combat.Hit, eChar.Torso)
				
				eHum.Animator:LoadAnimation(HitAnim):Play()
				
				
				
				local CharHRP = char.HumanoidRootPart
				local enemyHRP = eChar.HumanoidRootPart
				local attackDirection = (CharHRP.Position - enemyHRP.Position).Unit
				
				module.BodyVelocity (char.HumanoidRootPart, char.HumanoidRootPart, knockback, .2)
				
				if char:GetAttribute("Combo") >= 4 then 
					knockback = knockback * 5
					HelpfulModule.Ragdoll(eChar, RagdollTime)
				end
				module.BodyVelocity (eHRP, eHRP,-knockback * attackDirection, .2)
				
				StunHandlerV2.Stun(eHum, stunTime)
			end
			
		end
	end)
end
return module



And this is the server script that I had linked to the other module.

-- Services 
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local StarterPlayer = game:GetService("StarterPlayer")
local SoundService = game:GetService("SoundService")

-- Folders 
local WeaponsSounds = SoundService.SFX.Weapons
local RSStorage = RS.Storage
local RSModules = RSStorage.Modules
local SSModules = SS.Modules 
local Events = RSStorage.RemoteEvents
local AnimationsFolder = RSStorage.Animations
local WeaponAnimations = AnimationsFolder.Weapons

-- Events
local CombatEvent = Events.Combat
local CritEvent = Events.Critical


-- Modules 
local SoundsModule = require(RSModules.Combat.SoundsModule)
local ServerCombatModule = require(SSModules.CombatModule)
local HitService = require(SSModules.HitService)
local RayCastHitBox = require(SSModules.HitBoxes.RaycastHitboxV4)
local WeaponStats = require(SSModules.Weapons.WeaponStats)
local HelpfulModule = require (SSModules.MISC.Helpful)

-- Variables
local MaxCombo = 4



-- Main Scripting
CombatEvent.OnServerEvent:Connect(function(player)
	local char = player.Character
	local hum = char.Humanoid
	local torso = char.Torso
	
	if HelpfulModule.CheckForAttributes(char, true, true, true, true, true) then return end
	
	local currentWeapon = char:GetAttribute("CurrentWeapon")
	
	char:SetAttribute("Attacking", true)
	char:SetAttribute("Swing", true)
	
	ServerCombatModule.ChangeCombo(char)
	ServerCombatModule.stopAnims(hum)
	
	hum.WalkSpeed = 8
	hum.JumpHeight = 0
	--
	local Hitbox = RayCastHitBox.new(char[currentWeapon])
	
	
	
	
	local M1Anim = ServerCombatModule.getSwingAnimation(char,currentWeapon)
	local playSwingAnimation = hum.Animator:LoadAnimation(M1Anim)
	local TrailVFX = RSStorage.VFX.Weapons[currentWeapon].Trail:Clone()
	TrailVFX.Parent = char[currentWeapon]
	
	playSwingAnimation:GetMarkerReachedSignal("HitStart"):Connect(function()
		Hitbox:HitStart()
		-- Trail VFX
		TrailVFX.Enabled = true 
		for i,v in pairs (TrailVFX:GetChildren()) do
			if v.Name ~= "Trail2" then
				v.Enabled = true 
			end
		end
	end)
	
	playSwingAnimation:GetMarkerReachedSignal("HitEnd"):Connect(function()
		Hitbox:HitStop()
		-- Trail VFX
		TrailVFX.Enabled = false
		for i,v in pairs (TrailVFX:GetChildren()) do
			if v.Name ~= "Trail2" then
				
				v.Enabled = false 
			end
		end
		-- 
		local WeaponStat = WeaponStats.getStats(currentWeapon)
		local SwingReset = WeaponStat.SwingReset
		char:SetAttribute("Swing",false)
		if char:GetAttribute("Combo") == MaxCombo then 
			task.wait(0.5)
		else 
			task.wait(SwingReset)
		end
		char:SetAttribute("Attacking", false)
	end)
	
	playSwingAnimation.Stopped:Connect(function()
		Hitbox:HitStop() 
		if not char:GetAttribute("Swing") and not char:GetAttribute("IsBlocking") then 
			hum.WalkSpeed = StarterPlayer.CharacterWalkSpeed
			hum.JumpHeight = StarterPlayer.CharacterJumpHeight
		end
	end)
	
	playSwingAnimation:Play()
	
	SoundsModule.PlaySound(WeaponsSounds[currentWeapon].Combat.Swing, torso)
	
	local HitAnim = WeaponAnimations[currentWeapon].Hit["Hit"..char:GetAttribute("Combo")]
	
	HitService.Normal_HitboxHit(player,char,currentWeapon,Hitbox,HitAnim)
end)



-- Critical
CritEvent.OnServerEvent:Connect(function(player)
	local char = player.Character
	local hum = char.Humanoid
	local torso = char.Torso
	
	if HelpfulModule.CheckForAttributes(char, true, true, true, true, true) then return end

	local currentWeapon = char:GetAttribute("CurrentWeapon")

	char:SetAttribute("Attacking", true)
	char:SetAttribute("Swing", true)

	ServerCombatModule.ChangeCombo(char)
	ServerCombatModule.stopAnims(hum)

	hum.WalkSpeed = 0
	hum.JumpHeight = 0
	--
	local Hitbox = RayCastHitBox.new(char[currentWeapon])




	local M1Anim = ServerCombatModule.getSwingAnimation(char,currentWeapon)
	local playSwingAnimation = hum.Animator:LoadAnimation(M1Anim)
	local TrailVFX = RSStorage.VFX.Weapons[currentWeapon].Trail:Clone()
	TrailVFX.Parent = char[currentWeapon]

	playSwingAnimation:GetMarkerReachedSignal("HitStart"):Connect(function()
		Hitbox:HitStart()
		-- Trail VFX
		TrailVFX.Enabled = true 
		for i,v in pairs (TrailVFX:GetChildren()) do
			if v.Name ~= "Trail2" then
				v.Enabled = true 
			end
		end
	end)

	playSwingAnimation:GetMarkerReachedSignal("HitEnd"):Connect(function()
		Hitbox:HitStop()
		-- Trail VFX
		TrailVFX.Enabled = false
		for i,v in pairs (TrailVFX:GetChildren()) do
			if v.Name ~= "Trail2" then

				v.Enabled = false 
			end
		end
		-- 
		local WeaponStat = WeaponStats.getStats(currentWeapon)
		local CritReset = WeaponStat.CriticalReset
		char:SetAttribute("Swing",false)
		if char:GetAttribute("Combo") == MaxCombo then 
			task.wait(0.5)
		else 
			task.wait(CritReset)
		end
		char:SetAttribute("Attacking", false)
	end)

	playSwingAnimation.Stopped:Connect(function()
		Hitbox:HitStop() 
		if not char:GetAttribute("Swing") and not char:GetAttribute("IsBlocking") then 
			hum.WalkSpeed = StarterPlayer.CharacterWalkSpeed
			hum.JumpHeight = StarterPlayer.CharacterJumpHeight
		end
	end)

	playSwingAnimation:Play()

	SoundsModule.PlaySound(WeaponsSounds[currentWeapon].Combat.Swing, torso)

	local HitAnim = WeaponAnimations[currentWeapon].Hit["Hit"..char:GetAttribute("Combo")]

	HitService.Normal_HitboxHit(player,char,currentWeapon,Hitbox,HitAnim)
	
end)

It’s the second one I added a bunch of prints and it didn’t run any of them.

Figured out the problem it was a bug with the animation forgot to add in []

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