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

idk why it wont damage no errors at all how do i fix?


script.Parent.Parent.Damage.OnServerEvent:Connect(function(player,hit,done)
	local damhe = script.Parent.Parent.candama.Value

	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum and damhe then
		hum:TakeDamage(20)
		
		
	end
end)



the script that fire mote evnt


	script.Parent.Activated:Connect(function()
		
		if  not bussy then
			
			bussy = true

		aims.slash:Play()
		script.Parent.Handle.Touched:Connect(function(hit)
			hum = hit.Parent:FindFirstChild("Humanoid")
			if hum then
		script.Parent.Handle.Script.Disabled = false
				script.Parent.Damage:FireServer(hit)
				script.Parent.candama.Value = true
			end
			
			
			
		end)
		
		end
		wait(2)
		bussy = false
		script.Parent.candama.Value = false
	end)
	

end)

1 answer

✓ Accepted answer

On line 12 you send 'hit' which should be the limb part of a character. Since you want to damage the humanoid and you defined a humanoid in line 09 then why not just send that?

script.Parent.Handle.Touched:Connect(function(hit)
	hum = hit.Parent:FindFirstChildOfClass("Humanoid")
	if hum then
		script.Parent.Handle.Script.Disabled = false
		script.Parent.Damage:FireServer(hum) --sends the target humanoid
		script.Parent.candama.Value = true
	end
end)

The other issue in the same code above is line 06 where you set candama to true. The issue with this is that you're setting this on the client which wont replicate to the server. In the server script, the code probably still sees this BoolValue as false since it didn't replicate. Disabling the script here on line 04 also falls under this problem.

You could try removing this line and the if-statement in the server script but still might lack some security.

In the local script change the Touched event to this:

script.Parent.Handle.Touched:Connect(function(hit)
	hum = hit.Parent:FindFirstChildOfClass("Humanoid")
	if hum then
		script.Parent.Damage:FireServer(hum) --sends the target humanoid
	end
end)

Then you would change the server script to:

--server script

script.Parent.Parent.Damage.OnServerEvent:Connect(function(player, humanoid)
	if humanoid then
		humanoid:TakeDamage(20)
	end
end)

Let me know if you understood what I said or if I missed anything.

Edit: Make sure to also have a check to make sure hit isn't the player holding the tool! A few things left out which I can add in later if you need it.

Make sure the script that fires the remote event is a local script in the tool:

script.Parent.Activated:Connect(function()
	if not bussy then
		bussy = true
		aims.slash:Play()
		script.Parent.Handle.Touched:Connect(function(hit)
			local target = hit.Parent:FindFirstChildOfClass("Humanoid")
			if target then
				script.Parent.Damage:FireServer(target) --send target humanoid
			end
		end)
	end
	wait(2)
	bussy = false
end)

3 comments

0

it dint work

0

I looked at the model and it seems it was setting the LocalPlayer's Humanoid to the target humanoid. I provided fixed code at the bottom which basically makes a new local variable for the target humanoid.

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