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

How do you make part of a startercharacter deal damage?

I have a part inside of a model welded and inside of a starter character, and inside workspace, I have a damage script that's supposed to make the part deal damage. The problem is, it doesn't work. The part definately is touching other players, but it isn't dealing any damage. Here's the script.

local debounce = false 
local dmg = 27
	
function OnTouched(hit) 
		
		if hit.StarterPlayer.StarterCharacter.saberlight.blade ~= nil then
		if debounce == false and hit.StarterPlayer.StarterCharacter.saberlight.blade:findFirstChild("Humanoid") ~= nil then 
		debounce = true 
		hit.StarterPlayer.StarterCharacter.saberlight.blade:findFirstChild("Humanoid"):TakeDamage(dmg) 
		wait(1.2)
		debounce = false 
		
		end 
	end 
end 

script.Parent.Parent.StarterCharacter.saberlight.blade.Touched:connect(OnTouched)

1 answer

I would recomend adding some print() statements to check if everything works.

This is still your code and I have NOT fixed any evantual problems

local debounce = false
local dmg = 27

function OnTouched(hit)
	print("Touched")
	
	if hit.StarterPlayer.StarterCharacter.saberlight.blade ~= nil then
		print("saberlight.blade")
		if debounce == false and hit.StarterPlayer.StarterCharacter.saberlight.blade:FindFirstChild("Humanoid") ~= nil then
			print("Humanoid found")
			debounce = true
				hit.StarterPlayer.StarterCharacter.saberlight.blade:FindFirstChild("Humanoid"):TakeDamage(dmg)
			wait(1.2)
			debounce = false
			
		end
	end 
end

script.Parent.Parent.StarterCharacter.saberlight.blade.Touched:Connect(OnTouched)

If you see all the prints in the output I will try to understand where the problem lies.

4 comments

0

yes, it didn't print "humanoid found" in the output

0

But I did get an output that wrote script'Workspace.MyUsername.dmg1local', Line 20

0

Can you tell me how you would go about doing this?

0

No I don't actually. I will try to understand but can't today I'm sorry, I might try tomorrow

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