I have the localscript in the tool itself, and I have the script written so the sword doesn't do anything to players and damages enemies using a RemoteEvent. The swords don't seem to do damage after being cloned from a shop. This is strange as I have a sword that is put in StarterPack which uses this same script and it does damage. The sword tools are located alongside the RemoteEvent inside RemoteStorage.

Here is my ServerScriptService Script.

local function Damage(Player,hit,Enemy)
	local Character = Player.Character
	local Tool = Character:FindFirstChildOfClass("Tool")
	if (not Enemy) or (not hit) or (not Tool) then return end
	local Core = hit.Parent:FindFirstChild("HumanoidRootPart")
	if (not hit.Parent) or (not Core) then return end
	if (game.Players:GetPlayerFromCharacter(Enemy.Parent)) then return end
	local dmg = math.random(Tool.Min.Value,Tool.Max.Value)
	Enemy:TakeDamage(dmg)
	if Enemy.Health <= 0 then							
		local creator = Instance.new("ObjectValue",Enemy)
		creator.Name = "creator" 						 
		creator.Value = Character						 			
	end													 
	local ObjModel = CreateObject(hit,dmg)
	ObjModel:Destroy()
end

game.ReplicatedStorage.EnemyHit.OnServerEvent:Connect(Damage)

This is the script in my sword.

local debounce = false								  
local Tool     = script.Parent						  
local Handle   = Tool:WaitForChild("Handle")		  
ValueCooldown  = false								 
local SlashSound = Handle:WaitForChild("SlashSound")

function SwordCore(hit)															
	local Enemys = hit.Parent:FindFirstChildOfClass("Humanoid")					
	if script.CanDamage.Value and Enemys then						  		 	
		local EnemyHit = hit.Parent:FindFirstChild("Enemy")						
		local PlayerHit = hit.Parent:FindFirstChild("Humanoid")					
		local Character = Tool.Parent											
		local Player = game.Players:GetPlayerFromCharacter(Character)			
		if (not Player) then return end											
		local Humanoid = Character:FindFirstChild("Humanoid")					
		if (not Humanoid) then return end										
		if Enemys ~= Humanoid and (not debounce) then							
			if Enemys.Health <= 0 then return end								
			debounce = true														
			if PlayerHit then													
				game.ReplicatedStorage.PlayerHit:FireServer(hit,PlayerHit,Tool)	-- Fires The "PlayerHit" Event
			end																	
			if EnemyHit then													
				game.ReplicatedStorage.EnemyHit:FireServer(hit,EnemyHit,Tool)	
			end																	
			wait(0.7)															
			debounce = false													
		end																		
	end																			
end																			

function onActivated()										
	if (not Tool.Enabled) then return end					
	Tool.Enabled = false									
	local Character = Tool.Parent							
	local Humanoid = Character:FindFirstChild("Humanoid")	
	local Anim = Humanoid:LoadAnimation(Tool.Slash)			
	local SlashSound = Handle:WaitForChild("SlashSound")	
	if (Humanoid == nil) then return end					
	SlashSound:Play()										
	Anim:Play()												
	Tool.Unequipped:Connect(function()						
		Anim:Stop()											
	end)													
	wait(0.7)												
	Tool.Enabled = true										
end

function onEquipped()
	if (not Tool) then return end
	if (not Handle) then return end
	if Handle.UnsheathSound.IsPlaying == false then
		Handle.UnsheathSound:Play()
	end
end	

function onUnEquipped()
	if (not Tool) then return end
	if (not Handle) then return end
	Handle.UnsheathSound:Stop()
end	

function checkValue()
	if ValueCooldown           == false then
		ValueCooldown          = true
		script.CanDamage.Value = true
		wait(0.7)
		script.CanDamage.Value = false
		ValueCooldown          = false
	end
end

Tool.Activated:Connect(onActivated)
Tool.Activated:Connect(checkValue)
Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnEquipped)

Handle.Touched:Connect(SwordCore)

2 comments

0

Where is the server script? The server script will determine whether or not the humanoid being hid will take damage.

0

Whoops! Sorry, edited my post accordingly.