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

How do I make this code kill me when I touch the part?

I am making a coffee shop, and I would like to know what I am doing wrong. I am trying to make an ability to add flavor to a coffee cup that is active in their hand. Please inform me what I am doing wrong. Also, please note: I have not added the tool switch code yet, what is there is just to kill the player so I can test it.

local function onPartTouched(otherPart)


	local partParent = otherPart.Parent

	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
local part = script.Parent
local cup = humanoid.Character:FindFirstChild("Decaf") or humanoid.Character:FindFirstChild("Mocha") or humanoid.Character:FindFirstChild("Regular") or humanoid.Character:FindFirstChild("Frappe") or humanoid.Character:FindFirstChild("HotCococa") or humanoid.Character:FindFirstChild("Latte")
local debounce = false 
		if cup then
	humanoid.Health = 0
	end
	end
end


part.Touched:Connect(onPartTouched)

If possible, is there a way to be able to rename a tool without having to make a whole new one?

1 comment

0

Who uses :FindFirstChildWhichIsA() ??? I use :FindFirstChildOfClass()

2 answers

If you want to rename the tool, assuming the script is inside the tool

script.Parent.Name = "Water&WhippedCream"

and I'd recommend to just use print("CodeWorks!") instead of killing the player

the first thing i want to say: a humanoid doesnt have the property Character. the character is actually the parent of the humanoid. the other part of the script isnt that broken tho. heres the fixed version:

local debounce = false 
local function onPartTouched(otherPart) --a function
	local partParent = otherPart.Parent --the actual character
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid") --the humanoid
	local Character = partParent --character
	if humanoid then --if the humanoid exists then
		local cup = Character:FindFirstChild("Decaf") or Character:FindFirstChild("Mocha") or Character:FindFirstChild("Regular") or Character:FindFirstChild("Frappe") or Character:FindFirstChild("HotCococa") or Character:FindFirstChild("Latte")
		--debounce stays outside
		if cup then
			character:BreakJoints() --humanoid.Health = 0 works too
		end
	end
end
part.Touched:Connect(onPartTouched)
--how to rename something without making a whole new tool:
local object = workspace.Object
object.Name = "whatever u want"

hope that helped

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