Is there any way to make it so a part would not damage a certain player?

So i recently made a gojo reversal red script and i have been having this problem to not make the hitbox damage part go to the player and make the player doing it get no damage from other players. So honestly i have no idea

I did manage to do a thing that works but its broken and easily bypassable

i havent seen any articles about it so i would like to know if there is way to because not even going on most free models i found actual solutions

also heres the code images and videos about my problem:

image

(the attack script)

local re = script.Parent

local rockModule = require(game.ReplicatedStorage.RockModule)

re.OnServerEvent:Connect(function(player, tool)
	local char = player.Character
	local hum = char:FindFirstChild("Humanoid")
	
	local OldHealth = hum.Health
	
	task.wait()
	hum.WalkSpeed = 0.1
	tool.Handle.RedLight.Enabled = true
	tool.Handle.Middle.R.Enabled = true
	tool.Handle.Middle.W.Enabled = true
	tool.Handle.ParticleAttachment.C.Enabled = true
	tool.Handle.ParticleAttachment.O.Enabled = true
	tool.Handle.ParticleAttachment.S.Enabled = true
	tool.Handle.ParticleAttachment.SP.Enabled = true
	tool.Handle.ParticleAttachment.SW.Enabled = true
	wait(4.5)
	tool.Handle.RedLight.Enabled = false
	tool.Handle.Middle.R.Enabled = false
	tool.Handle.Middle.W.Enabled = false
	tool.Handle.ParticleAttachment.C.Enabled = false
	tool.Handle.ParticleAttachment.O.Enabled = false
	tool.Handle.ParticleAttachment.S.Enabled = false
	tool.Handle.ParticleAttachment.SP.Enabled = false
	tool.Handle.ParticleAttachment.SW.Enabled = false
	rockModule.Crater(char.HumanoidRootPart.CFrame, 7, 7, 10, true)
	hum.Health = math.huge
	local hitbox = game.ReplicatedStorage.HitBox:Clone()
	hitbox.Parent = game.Workspace.Debris
	hitbox.Position = char.HumanoidRootPart.Position
	local spr = hitbox.DamageScript
	local spr2 = hitbox.explosionscript
	spr.Enabled = true
	spr2.Enabled = true
	hitbox.Transparency = 0.5
	wait(2)
	hum.Health = OldHealth
	hitbox:Destroy()
	hum.WalkSpeed = 16
end)

and the script in the hitbox part:

local part = script.Parent

local db = false

part.Touched:Connect(function(touched)
	if db == false then
		db = true
		local hum = touched.Parent:FindFirstChild("Humanoid")
		hum:TakeDamage(20)
		wait(3)
		db = false
	end
end)

1 Like

Don’t understand what you’re looking for here…

im looking for the hitbox part that i made not deal damage while u can also not lose damage but it being a better way than i did seeing if there are any other methods out there

I need to see the way your code is organized, but I would try setting an attribute to the hitbox called “Owner” or smth like that and pass in the players username then get that attribute in your hit function and then use game.Players:GetPlayerFromCharacter function to determine whether or not its touching the owner of that attack.

yes thats what i was aiming for but i also wanted it so the player cant get damage from others or else it would interrupt the ability. Also heres the local script code for more context:

local player = game.Players.LocalPlayer
local chara = player.Character
local tool = script.Parent
local players = game.Players

local re = script.RemoteEvent
local canab = game.ReplicatedStorage.Values.CanAbility

local mouse = player:GetMouse()
if canab.Value == false then
	if mouse.Target and mouse.Target.Parent:FindFirstChild("Humanoid") then
		local thum = mouse.Target.Parent:FindFirstChild("HumanoidRootPart")
		canab.Value = true
		if canab.Value == true then
			tool.Activated:Connect(function()
				chara:WaitForChild("HumanoidRootPart").CFrame = thum.CFrame * CFrame.new(0, 0, -5)
			end)
		end
	end
end

local animationId = "99910051876265"

local animationPriority = Enum.AnimationPriority.Action

local function playAnimation(player)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid then
		local animation = Instance.new("Animation")
		animation.AnimationId = "rbxassetid://" .. animationId

		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack.Priority = animationPriority
		animationTrack:Play()
	end
end

local db = false

function toolActivation()
	if db == false then
		db = true
		if canab.Value == true then
			script.Parent.Handle.gr:Play()
			local Player = game.Players:GetPlayerFromCharacter(tool.Parent)
			if Player then
				playAnimation(Player)
			end
			re:FireServer(tool)
		end
		wait(10)
		db = false
	end
end

tool.Activated:Connect(toolActivation)

also the values:
image

It’s not finished the script so ingnore the mouse part i was gonna make so it teleports to the player and yes its working, aswell as the vfx from the explosion will be modified.

That’s what I said earlier that you set an attribute for the damage part and set the value to the player who did the attacks name I’ll send some code later

Sorry my timezone is diferent so at the time i had to sleep, so ok i will try it, i thought u were saying to put a script to detect the attack being done ( thats why i made it in health for the two ) so like you’re saying i might just need to add attributes and it really is the best way. Also sorry if my grammar is bad im brazilian and new to the devforum i just wanted to know if there was any better way to do than that, but there isn’t much more and i might just end this thread so yeah thanks for helping me

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.