For some reason my sword activation is activating for both players?

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to make a sword fighting system(clearly not done)

  2. What is the issue? Include screenshots / videos if possible!
    When an player clicks it attacks for both players

Script(Server)

local hitable = script.Parent.Attacking.Value
local player = script.Parent.Parent.Parent
script.Parent.Handle.Touched:Connect(function(hit)
	print("D")
	if hit.Parent:FindFirstChild("Humanoid") then
		print("F")
		if hitable == true then
			print("A")
			if hit.Parent.Name ~= player.Name then 
			if hit.Parent:FindFirstChild("Blocking").Value == 1 then
				print("C")
				hitable = false
				script.Parent["hftf block hit"]:Play()
				hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 5
			elseif hit.Parent:FindFirstChild("Blocking").Value == 0 then
				script.Parent.Slash1:Play()
				hitable = false
				hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 15
				hit.Parent:FindFirstChild("Humanoid").WalkSpeed = 10
				game.ReplicatedStorage.HitPlayer:FireClient(game.Players:FindFirstChild(player.Name))
				task.wait(2)
				hit.Parent:FindFirstChild("Humanoid").WalkSpeed = 16
				elseif hit.Parent:FindFirstChild("Blocking").Value == 2 then
					print("Parry")
					hitable = false
				script.Parent.Parry:Play()
				print("YES")
				script.Parent.Handle:FindFirstChild("ParticleEmitter").Enabled = true
				local player = hit.Parent
				game.ReplicatedStorage.ParryWorked:FireClient(game.Players:FindFirstChild(player.Name))
				task.wait(0.2)
					script.Parent.Handle:FindFirstChild("ParticleEmitter").Enabled = false
					end
			end
		end
	end
end)
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(Player)
	hitable = true
	script.Parent.Handle.Trail.Enabled = true
end)
game.ReplicatedStorage.HitStop.OnServerEvent:Connect(function(Player)
	hitable = false
	script.Parent.Handle.Trail.Enabled = false
end)
game.ReplicatedStorage.Block.OnServerEvent:Connect(function(Player,humananoid)
	game.Workspace:FindFirstChild(humananoid.Name).Blocking.Value = 1
end)
game.ReplicatedStorage.BlockStop.OnServerEvent:Connect(function(Player,humananoid)
	game.Workspace:FindFirstChild(humananoid.Name).Blocking.Value = 0
end)
game.ReplicatedStorage.Parry.OnServerEvent:Connect(function(Player,humananoid)
	game.Workspace:FindFirstChild(humananoid.Name).Blocking.Value = 2
end)

Script(Local)

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local block2 = false
local unblocktime = false
local nameplayer = game.Players.LocalPlayer
local humananoid = game.Workspace:WaitForChild(nameplayer.Name):WaitForChild("Humanoid")
local Katana = game.Players.LocalPlayer:FindFirstChild("Backpack"):FindFirstChild("Katana") or humananoid.Parent:FindFirstChild("Katana")
local anim = humananoid:LoadAnimation(Katana.HoldingAnim)
local animblock = humananoid:LoadAnimation(Katana.BlockAnim)
local animslash = humananoid:LoadAnimation(Katana.SlashAnim)
local action = false
local hitable = Katana.Attacking.Value
local blocking = humananoid.Parent.Blocking.Value
UIS.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.F then
		if game.Players.LocalPlayer.Character:FindFirstChild("Katana") then
			if action == false then
			block2 = true
            unblocktime = false
			anim:Stop()
			animblock:Play()
				action = true
				unblocktime = false
				block = true
				game.ReplicatedStorage.Parry:FireServer(Player,humananoid)
				task.wait(0.2)
				game.ReplicatedStorage.Block:FireServer(Player,humananoid)
				task.wait(0.4)
				print("BOO")
				unblocktime = true
			end
	end
	end
	end)
UIS.InputEnded:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.F then
		if block2 == true then
			repeat
				wait()
			until unblocktime == true
			block2 = false
			animblock:Stop()
			action = false
			block = false
			game.ReplicatedStorage.BlockStop:FireServer(Player,humananoid)
			end
				end
end)
Katana.Equipped:Connect(function()
	anim:Play()
end)
Katana.Unequipped:Connect(function()
	animblock:Stop()
	animslash:Stop()
	anim:Stop()
end)
Katana.Activated:Connect(function(Player)
	if action == false then
		game.ReplicatedStorage.Hit:FireServer(hitable)
		animslash:Play()
		animblock:Stop()
		anim:Stop()
		action = true
	end
end)
animslash.Stopped:Connect(function(Player)
	game.ReplicatedStorage.HitStop:FireServer(hitable)
	anim:Play()
	action = false
end)
game.ReplicatedStorage.ParryWorked.OnClientEvent:Connect(function()
	animslash:Stop()
end)

It looks like your script is setup to be inside the tool of your weapon, and the local and server scripts refer to a event in RepStg

So if local client A triggers, it fires to RepStg, and since every katana listens to the same event they all receive this notice and activate as specified. What you can do is either

  1. Make the remote event inside the tool, and have the script refer to that event, this will make each script refer to it’s own remote event so that other tools don’t receive the notices
  2. Update your current scripts to pass the information of the tool being used to the server, and from the server only allow the tool being passed to be activated

I think that’d fix up your issue

1 Like

Thank you so much
I completely forgot about the other katanas firing cus of the remote events
And do I have to still do the second thing cus it already works