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

attempt to index global 'death' (a function value)?

I'm trying to make a nuke that calls :BreakJoints() on humanoids in game. I keep getting this error though not sure what I'm doing wrong.

13:20:57.457 - Workspace.Brick.Script:23: attempt to index global 'death' (a function value) 13:20:57.457 - Stack Begin 13:20:57.458 - Script 'Workspace.Brick.Script', Line 23 13:20:57.458 - Stack End

function Cough(Part)
local fries = Instance.new('Message')
fries.Parent = game.Workspace
fries.Text = "Hello I will now explode"
wait(3)
fries:Destroy()
local explosion = Instance.new('Part', game.Workspace)
Part = explosion
Part.Anchored = true
Part.Shape = 'Ball'
Part.Transparency = 0.1
Part.TopSurface = "Smooth"
Part.BottomSurface = "Smooth"
Part.CanCollide = false
while true do
Part.Size = Part.Size + Vector3.new(10,10,10)
wait()
end

end
hum = game.Workspace:FindFirstChild("Humanoid")
function death(hum)
	if death.Touched:FindFirstChild(hum)then
		hum:BreakJoints()
		end
end

script.Parent.Touched:connect(Cough)
game.Workspace.Brick.Touched:connect(death)
wait(10)



2 answers

A function cannot be touched. Instead, a 3D part can be. Also, .Touched is not a property. I am going to rewrite the stuff.

function Cough(Part)
local fries = Instance.new('Message')
fries.Parent = game.Workspace
fries.Text = "Hello I will now explode"
wait(3)
fries:Destroy()
local explosion = Instance.new('Part', game.Workspace)
Part = explosion
Part.Anchored = true
Part.Shape = 'Ball'
Part.Transparency = 0.1
Part.TopSurface = "Smooth"
Part.BottomSurface = "Smooth"
Part.CanCollide = false
while true do
Part.Size = Part.Size + Vector3.new(10,10,10)
wait()
end

end
local deb = false
hum = game.Workspace:FindFirstChild("Humanoid")
function death(hum)
    if hum:FindFirstChild('Humanoid') and deb == false then --I'm assuming you are checking for a humanoid. I'm confused as what you wanted here.
	deb = true
        hum:BreakJoints()
	wait(1)
	deb = false
        end
end

script.Parent.Touched:connect(Cough)
game.Workspace.Brick.Touched:connect(death)
wait(10) --A wait here does nothing, as there is no code after the wait.

7 comments

0

I am trying to do a check for if the part was touched by a humanoid. And if you can I cant figure out how to make the function happen once instead of happening thousands of times when you step on the brick.

0

Ohh ok

0

well do you know how i can fix it? xd

0

I DID I JUST MADE AN EDIT Ok?

0

bud i asked becuase you didn't fix it, OK?

0

DID YOU EVEN COPY THE NEW SCRIPT?

0

Yeah I did it still doesn't work for me. PLUS I already made a different version and that still doesn't work

the "hum" at line 21 is useless, remove it. the touched event returns the part that touched it. so to check if a player has touched it, and has a humanoid then remove the death function and put this instead:

death = function(part)
	if part.Parent:FindFirstChild"Humanoid" then
		part.Parent.Humanoid:BreakJoints()
	end
end

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