Weapon script only works for one player at a time/ stops working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make it so that the weapon is able to be used by any player, and not one at a time.
  2. What is the issue? Include screenshots / videos if possible!
    https://streamable.com/tpsv0q
    The weapon can be used, but it can only be used by one player, and sometimes it completely stops functioning.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried to locate an answer for my problem with no luck so far.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you! I’m quite new to scripting.
-- The Local Script 
wait(2)

local unequipped = false


local animation = Instance.new("Animation")
animation.Name = "Idle"
animation.Parent = script.Parent

local humanoid = game.Players.LocalPlayer.Character:WaitForChild('Humanoid')
animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "6186810966"
local animtrack = humanoid:LoadAnimation(animation)

script.Parent.Equipped:Connect(function()
	animtrack:Play()
	unequipped = false
	
end)
script.Parent.Unequipped:Connect(function()
	animtrack:stop()
	unequipped = true
	game.ReplicatedStorage.Excalibur:FireServer( unequipped)
end)

script.Parent.Activated:Connect(function()
	
	
		game.ReplicatedStorage.Excalibur:FireServer(  unequipped)
	
		
		
end)
The Server Script
-- >>: Excalibur


local exAttack = true
local function ExcaliburHitbox(p) 
	for i,v in pairs (workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			if v ~= p.Character then
				if v.Humanoid.Health > 0 then
					
					local HRP = p.Character.HumanoidRootPart
					local r = Ray.new(HRP.Position, HRP.CFrame.LookVector * 500)
					local hit =  workspace:FindPartOnRay(r,HRP)

						if hit then
							print(hit)
								if hit.Parent:FindFirstChild("Humanoid") then
									if (v.HumanoidRootPart.Position - p.Character.HumanoidRootPart.Position).magnitude <=5 then
										exAttack = false
										v.Humanoid:TakeDamage(50)
										print("damaged")
										exAttack = true
								end
							end
						end
					end
				end
			end
		end
	end

weaponCooldown = Instance.new("BoolValue")
weaponCooldown.Value = true
weaponCooldown.Name = "exdb"
ComboChecker = 0

game.ReplicatedStorage.Excalibur.OnServerEvent:Connect(function(p, unequip)
	weaponCooldown.Parent = p
	
	print( p:WaitForChild("exdb").Value)
	spawn(function()
		while true do
			wait()
			p.Character.Humanoid.Died:Connect(function()
				p.exdb.Value	 = true
				
			end)
		end
	end)
	if unequip == true then
		wait(2)
		p.exdb.Value = true
	end
	
	if p.exdb.Value == true then
		p.exdb.Value = false
			if ComboChecker == 0 then

				print('1')
				
				local animId = "rbxassetid://3101922409"
                                animator = p.Character.Humanoid:FindFirstChildOfClass("Animator")
				animationExc = Instance.new('Animation')
				animationExc.AnimationId = animId
				track = animator:LoadAnimation(animationExc)
				compareTime = tick()
				track:Play()
				ExcaliburHitbox(p)
				track.Stopped:wait()
				wait(1)
				ComboChecker = 1
				p.exdb.Value = true
			elseif ComboChecker == 1 then
				p.exdb.Value = false
				local TimeUntilResetCombo = tick() - compareTime

				if TimeUntilResetCombo <= 5 then

					print('2')
					animId = "rbxassetid://3101877315"
					animationExc.AnimationId = animId
					track = p.Character.Humanoid:LoadAnimation(animationExc)
					track:Play()
					ExcaliburHitbox(p)
					track.Stopped:wait()
					ComboChecker = 1
					p.exdb.Value = true
				elseif TimeUntilResetCombo >5 then
					ComboChecker = 0
					p.exdb.Value = true
			end

		end
	end
end)

Any assistance would be appreciated.

Humanoid:LoadAnimation() is depreciated. Use Animator. Also on the server side, not sure why you iterate through the objects of workspace to find humanoid. The humanoid exists inside of a character model of a player.

I will read on animator. Also, I did that in order to search for a humanoid for the weapon to do damage to.

You won’t find any humanoid unless you do workspace:GetDescendants() or manually loop over players’ character to get humanoid.

Oh, I will try that, but what I previously did managed to do damage to the humanoid of a nearby character as well.

This is also depreciated. See FindPartOnRay.

1 Like