How to solve this problem?

Bruh, bruh, bruh.
Me need help, please. Im maked the function onDmg() and make the function checking on touched
if humanoid.Parent.Name ~= LocalPlayer.Name them
print(“Attacked is a”…attackNPC)
end

In the console writing the “Attacked the NPC-Thug”, not my player-nickname.
BUT ATTACKED HAS BEEN IM… bruhh… help me please

Uh what?

Could you format your code in code blocks instead so that it’s easier for us to intercept the issue?

1 Like

what is this? firstly the title does not include the problem, secondly the body is massive hard to read text because you didn’t use code blocks.

`

local function onDmgFSPOKE(hit)
   if hit and hit.Parent:FindFirstChild('Humanoid') then
	local hum =  hit.Parent:FindFirstChild('Humanoid')
	if hum.Parent.Name ~= game.Players.LocalPlayer.Name then
		if damagePoke == true then
			print("Attack is a "..hum.Parent.Name)
			damagePoke = false
			local damages = math.random(0.01, 0.05)
			hum:TakeDamage(damages)
			wait(0.01)
			damagePoke = true
		end
	end
  end
end

`

1 Like

Question: Is this a Local or Server Script?

This script is localscript (for one player)
Means:
My game for one player only

What is the goal of this script?

1 Like

Damage the NPC from Punch attack

I do see a couple issues that could be changed about this script:

  • You could just define the Character instead of having to put hum.Parent each time you use it
  • I believe math.random will only accept integers (Or whole numbers) and not decimals, you could fix this by doing
local damages = math.random(100, 500) * 0.0001
  • A slight reminder that client-replication across the server will act very strange, so if the target dies the chances will only be made to the client, do use a RemoteEvent inside ReplicatedStorage to handle client-server transportation to be able to deal damage on the server side instead
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local function onDmgFSPOKE(hit)
   if hit and hit.Parent:FindFirstChild('Humanoid') then
    local Target = hit.Parent
	local hum = Target:FindFirstChild('Humanoid')
	if Target.Name ~= game.Players.LocalPlayer.Name and damagePoke == true then
		print("Attack is a "..Target.Name)
		damagePoke = false
		local damages = math.random(0.01, 0.05) * 0.0001
		Event:FireServer(Target, damages)
		wait(0.01)
	    damagePoke = true
	end
  end
end
--ServerScript in ServerScriptService
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player, Target, DamageResult)
    Target.Humanoid:TakeDamage(DamageResult)
end)

First of all, please learn how to properly format a post so people can assist you better. Omit unnecessary remarks and keep straight to the point. Include your issue in your post title, and go into details in your post. Properly format your code using code blocks.

Second of all, this is a code snippet, and absolutely no context is given, so there’s not much anyone can do to help.

Currently, print("Attack is a "..hum.Parent.Name) will print the name of the “thing” that is being attacked. I’m not sure if this is what your goal is.

1 Like

Doesn’t work. My later functions with damage NPC working succesfuly. They were writed in the LocalScript. With RemoveEvent, gives the “Attacked the NPC-Thug and taked the 0.016 damage”.
My script same how like your. With LocalScript he gives the same messages. But, this problem isn’t solved. Im died from the my damage, but func print writing that damaged the NPC. My nickname is CatMadeInHeaven, else, if was attacked im, im be died and func print writed that attacked im with how many damage. This function Touched has been setted to my hands. (Right and Left), and im makes the continion with check, who has been attacked, because dont die.

Im checked, this is my NPC which im must damage.

How do you keep dying though? That wouldn’t make sense if you’re firing a Touched event and checking if it’s not equal to the LocalPlayer’s Name

Another thing that I see is that you have your cooldown way too fast…?

Im actually dont know why, im now doing checking the algorithm of script. If im detect the break logic of script, im say. And no, if im have the fast regeneration, then im not be died.

Probably, the break logic of script - this is my hands. Im maked the animation with touching hands. But… The condition who checked the name of character, where location of this hands, completing succesfuly, printed the name of enemy and no way hands can’t be the problem of breaking logic… Maybe, im create the connection of function to hands enemy?.. Hmmm… if this was true, then me need was go to enemy very near, but since, im taking damage on the distant of enemy… This is false, and, im use the punch and dont take the damage. If im attacked the enemy, im taking the damage… Im try to use function print when im use this “damage” function. Bruh, im using the punches, and function nothing wroted. Hmmm… If function nothing enter in the console, then… Сollision with something called the damage… Im tryed to attack the part, nothing happened. When im attacked the humanoid… Then… im take the damage… Hmm, maybe own condition problem to break logic of script.

Im succesfuly cleared the condition, problem not solved… BRUHHH

Okay, the logic of function:

  1. Checking if the touched have the “Humanoid” – Correctly.
  2. Creating the var with value of this Touched “humanoid” – Correctly.
  3. Checking on value of cannable to use this func. – Correctly, true, continue.
  4. Write the attacked Humanoid parent name. – Correctly, [THUG]
  5. Change var cannable to false. – Correctly, continue all code to end of script to stop.
  6. Setting the damage. – Correctly.
  7. Called the remoteEvent with arguments: Touched.Humanoid and damage. – Correctly.
  8. Wait(0.9)
  9. Change the var cannable to true to continue code.
    BRUUHHH

Im going to print health of enemy. Maybe im can understand what is a problem. -.

BRUHHHHH… Im understand what happened. Im checking on .Touched:FindFirstChild(“Humanoid”)
if Part dont have the humanoid, the function doesnt be working. If im attacked the NPC, who have the humanoid, the code in function succesfuly complecting, im think that im just use own humanoid…