How to make a part do damage

I want my ability to do damage but I don’t know how to do that. I want it so that when a player that’s not the player that started the ability touches the SphereClone then they take damage.

Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local AttackFolder = ReplicatedStorage:WaitForChild("Attacks")
local Sphere = AttackFolder:WaitForChild("Sphere")
local OuterSphere = AttackFolder:WaitForChild("OuterSphere")
local Wave = AttackFolder:WaitForChild("Wave")

-- Tween Info --
local TInfo1 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local TInfo2 = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

script.Parent:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(player)
	local Humanoid = player.Character.Humanoid
	local HumanoidRP = player.Character.HumanoidRootPart
		
	local SphereClone = Sphere:Clone()
	local OuterSphereClone = OuterSphere:Clone()
	local WaveClone = Wave:Clone()
	
	-- Tweens --
	local Sphere1Tween = TweenService:Create(SphereClone, TInfo1, {Transparency = 0, Size = Vector3.new(30,30,30)})
	local OuterSphere1Tween = TweenService:Create(OuterSphereClone, TInfo1, {Transparency = 0, Size = Vector3.new(32, 32, 32), Orientation = Vector3.new(0, 5000,0)})
	local Wave1Tween = TweenService:Create(WaveClone, TInfo1, {Transparency = 0, Size = Vector3.new(42.715, 5, 47.272), Orientation = Vector3.new(0, 5000,0)})
	
	local Sphere2Tween = TweenService:Create(SphereClone, TInfo2, {Transparency = 1, Size = Vector3.new(100,100,100)})
	local OuterSphere2Tween = TweenService:Create(OuterSphereClone, TInfo2, {Transparency = 1, Size = Vector3.new(100, 100, 100)})
	local Wave2Tween = TweenService:Create(WaveClone, TInfo2, {Transparency = 1, Size = Vector3.new(100, 100, 100)})
	
	-- Clone Properties --
	SphereClone.Parent = workspace
	OuterSphereClone.Parent = workspace
	WaveClone.Parent = workspace
	SphereClone.Position = HumanoidRP.Position
	OuterSphereClone.Position = HumanoidRP.Position
	WaveClone.Position = HumanoidRP.Position
	SphereClone.Position = Vector3.new(SphereClone.Position.X, SphereClone.Position.Y/2, SphereClone.Position.Z)
	OuterSphereClone.Position = Vector3.new(OuterSphereClone.Position.X, OuterSphereClone.Position.Y/2, OuterSphereClone.Position.Z)
	WaveClone.Position = Vector3.new(WaveClone.Position.X, WaveClone.Position.Y/2, WaveClone.Position.Z)
	
	Sphere1Tween:Play()
	OuterSphere1Tween:Play()
	Wave1Tween:Play()
	wait(1)
	Sphere2Tween:Play()
	OuterSphere2Tween:Play()
	Wave2Tween:Play()
	wait(1)
	SphereClone:Destroy()
	OuterSphereClone:Destroy()
	WaveClone:Destroy()	
end)
1 Like

Create a touch event within the objects, and just deal damage to the humanoid

Use a server script!

Here are some links:

https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched
https://developer.roblox.com/en-us/api-reference/function/Humanoid/TakeDamage

3 Likes

This is my code but how do I make it not damage the person who started it

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	local debounce = false
	local cooldown = 0.5
	if hit and humanoid and not debounce then
		debounce = true
		humanoid.Health -= 20
		wait(cooldown)
		debounce = false
	end
end)

And also it kills me instantly for some reason

1 Like

You could create a global variable with _G, or a object value in RepStorage with the Player who started it

and then in your .touched just do a player check via

using GetPlayerFromCharacter you can get the player that way

and then compare the starter player to the hit player

2 Likes

But what if there are multiple people doing it at once?

Touching the object or starting the orb?

1 Like

starting the orb (have to add this in because of character limit)

What you could do is after you clone the object

Either use
AddTag
GetTags
or
SetAttribute
GetAttribute
or
Create an object value and parent it to the orb.

2 Likes

I get an error on this line:

SphereClone:GetAttribute("Owner").Value = player.Name

Am I doing something wrong?

SphereClone:SetAttribute("Owner", player.Name)

and then to get it

local Owner = SphereClone:GetAttribute("Owner")
2 Likes

Your awesome but some things not working its printing that I’m the owner of the orb and doesn’t do damage to me but it also does not do damage to anything else.

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	local debounce = false
	local cooldown = 0.5
	if hit and humanoid and not debounce and not hit.Name == script.Parent:GetAttribute("Owner") then
		debounce = true
		humanoid.Health -= 20
		wait(cooldown)
		debounce = false
	end
end)

hit.Parent.Name

since hit.name would most likely be a body part

1 Like

For some reason it still does not work

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	local debounce = false
	local cooldown = 0.5
	if hit and humanoid and not debounce and not hit.Parent.Name == script.Parent:GetAttribute("Owner") then
		debounce = true
		humanoid.Health -= 20
		wait(cooldown)
		debounce = false
	end
end)

Is everything on the serverside and or client side, they have to be on the same

so example the touched has to be a server script if the attribute is a serverscript

1 Like

image
image

Inside the Attack1 script is this:

local UserInputService = game:GetService("UserInputService")
local CanAttack = true
local Cooldown = 5

UserInputService.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end

	if input.KeyCode == Enum.KeyCode.E and CanAttack == true then
		CanAttack = false
		script:WaitForChild("RemoteEvent"):FireServer()
		wait(Cooldown)
		CanAttack = true
	elseif input.KeyCode == Enum.KeyCode.E and CanAttack == false then
		print("Your on cooldown")
	end
end)

Uhhhh, is the touched event working properly?

You could do some debug prints trying to see what it stops at for example


script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    local debounce = false
    local cooldown = 0.5

    if not hit then return end
    warn'Hit Passed'
    if not humanoid then return end
    warn'humanoid Passed'
    if not debounce then return end
    warn'debounce Passed'
    if hit.Name == script.Parent:GetAttribute("Owner") then return end
    warn'hitname Passed'

    debounce = true
    humanoid.Health -= 20
    wait(cooldown)
    debounce = false
end)

Edit: I fixed some code retry sorry!
Edit2: Fixed again!

1 Like

I get a red underline

image

you have to put a Then There heres a fixed code

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	local debounce = false
	local cooldown = 0.5

	if not hit then return end
	warn'Hit Passed'
	if not humanoid then return end
	warn'humanoid Passed'
	if not debounce then return end
warn'debounce Passed'
if hit.Name == script.Parent:GetAttribute("Owner") then return end
warn'hitname Passed'

debounce = true
humanoid.Health -= 20
wait(cooldown)
debounce = false
end)

1 Like

Sorry, either re copy my message or the one above this. Typed it a little too fast!

1 Like

Everything goes through
image