Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make my sword not damage other players?

I want my sword to not damage other players.

Here are the scripts it currently has: In ServerScriptService (normal script)



local cooldowns = {}


game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
		local m6d = Instance.new("Motor6D", character.RightHand)
		m6d.Part0 = character.RightHand
		m6d.Name = "ToolM6D"
	end)
end)


game.ReplicatedStorage.SwordRE.OnServerEvent:Connect(function(player, instruction, bodyAttach)
	
	if instruction == "connectm6d" then
		
		player.Character.RightHand.ToolM6D.Part1 = bodyAttach
		
	elseif instruction == "disconnectm6d" then
		
		player.Character.RightHand.ToolM6D.Part1 = nil
		
		
	elseif instruction == "attack" then
		
		if cooldowns[player] then return end
		
		cooldowns[player] = true
		
		
		game.ReplicatedStorage.SwordRE:FireAllClients(bodyAttach)
		
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {player.Character}
		
		local raycastResults = workspace:Raycast(player.Character.HumanoidRootPart.Position, player.Character.HumanoidRootPart.CFrame.LookVector * 3, raycastParams)
		
		if raycastResults and raycastResults.Instance.Parent:FindFirstChild("Humanoid") then
			
			raycastResults.Instance.Parent.Humanoid:TakeDamage(20)
		end
		
		wait(0.5)
		
		cooldowns[player] = false
	end
end)

In StarterPack (local script)

local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

local idleAnim = character:WaitForChild("Humanoid"):LoadAnimation(script.IdleAnimation)

local animCombo = {
	character:WaitForChild("Humanoid"):LoadAnimation(script.Swing1Animation),
	character:WaitForChild("Humanoid"):LoadAnimation(script.Swing2Animation),
	character:WaitForChild("Humanoid"):LoadAnimation(script.Swing3Animation),
}

local currentCombo = 1
	
	
script.Parent.Equipped:Connect(function()
	
	game.ReplicatedStorage.SwordRE:FireServer("connectm6d", script.Parent.BodyAttach)
	
	character.RightHand.ToolM6D:GetPropertyChangedSignal("Part1"):Wait()
	idleAnim:Play()
end)


script.Parent.Unequipped:Connect(function()

	game.ReplicatedStorage.SwordRE:FireServer("disconnectm6d")
	
	idleAnim:Stop()
end)


local cooldown = false

script.Parent.Activated:Connect(function()
	
	if cooldown then return end
	
	cooldown = true
	
	game.ReplicatedStorage.SwordRE:FireServer("attack", script.Parent.BodyAttach)
	
	animCombo[currentCombo]:Play()
	
	character.HumanoidRootPart.Velocity = character.HumanoidRootPart.CFrame.LookVector * 100 * Vector3.new(1, 0, 1)
	
	currentCombo += 1
	if currentCombo > #animCombo then currentCombo = 1 end
	
	local previousCombo = currentCombo
	
	spawn(function()
		
		wait(3)
		
		if currentCombo == previousCombo then
			currentCombo = 1
		end
	end)
	
	wait(0.5)
	
	cooldown = false
end)


game.ReplicatedStorage.SwordRE.OnClientEvent:Connect(function(bodyAttach)
	
	bodyAttach.Slash:Play()
	
	bodyAttach.Trail.Enabled = true
	wait(0.3)
	bodyAttach.Trail.Enabled = false
end)

Thanks!

1 answer

✓ Accepted answer

Remove this line

raycastResults.Instance.Parent.Humanoid:TakeDamage(20)

Which can be found on line 42 of your server script.

This discussion is preserved as it was. New answers, comments, and votes are closed.