Hey, I’m trying to make a lava brick that kills you when you touch it, I’ve followed the tutorials on the Roblox DevHub, and yet this doesn’t seem to be working…
local function killPlayer(touchedPart)
print ("Function 'killPlayer' ran.")
local partParent = touchedPart.Parent
local humanoid = partParent:FindFirstChild("Humanoid")
if humanoid == true then
humanoid.Health = 0
end
end
brick.Touched:Connect(killPlayer)
I suppose that this goes under the “extremely basic” part of the scripting support category… oh well. Any help would be appreciated, thank you!
you must make sure it is not a local script but a script first then try simplify it to understand it more like:
local function killPlayer(hit)
print ("Function 'killPlayer' ran.")
local Char = hit.Parent
if Char:FindFirstChild("Humanoid") then
local humanoid = Char:FindFirstChild("Humanoid")
humanoid.Health = 0
end
end
brick.Touched:Connect(killPlayer)
local function killPlayer(touchedPart)
print ("Function 'killPlayer' ran.")
local partParent = touchedPart.Parent
local humanoid = partParent:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
humanoid.Health = 0
end
brick.Touched:Connect(killPlayer)
So that would mean a script that looks like this(full script):
local brick = script.Parent
local function killPlayer(hit)
print ("Function 'killPlayer' ran.")
local Char = hit.Parent
if Char:FindFirstChild("Humanoid") then
local humanoid = Char:FindFirstChild("Humanoid")
humanoid.Health = 0
end
end
brick.Touched:Connect(killPlayer)
local brick = script.Parent
local function killPlayer(hit)
print ("Function 'killPlayer' ran.")
local Char = hit.Parent
local humanoid = Char:FindFirstChild("Humanoid")
if not humanoid then return end
humanoid.Health = 0
end
brick.Touched:Connect(killPlayer)
Edit: replied t othe wrong person, meant to reply to @AC_Starmarine
Are you sure that the script that this code is in is a normal script? not a local script. Also that the script’s parent is in the brick you want to touch to kill you?