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

Character dies on touch?

Im trying to make the part that the character is touching disapear but instead the character is killed when i do this.

This is the script


food = Instance.new("Part", game.workspace.foodlist)

food.Touched:connect(function(food)
	_G.score.Value = _G.score.Value + 1
	food:Destroy()
end)

1 answer

✓ Accepted answer

It's probably best not to put "food" as the parameter of the function as you have already used it on line 1. It may cause confusion as to what is what.

local food = Instance.new("Part", game.workspace.foodlist)

food.Touched:connect(function(hit)
    _G.score.Value = _G.score.Value + 1
    food:Destroy()
end)

Does that work?

8 comments

0

That still kills the character

0

It also makes the parts stack on top of each other

0

Whoops, I accidentally put "hit" on line 5. I've edited it now. Does it work or does it still kill the character?

0

Nope nothing happens

0

It dosent kill the character tho

0

I have another script that randomly generates these food parts accross the map, and i limited it to max 10 instances and i figured out that it removes one of the parts but not the one its touching

0

Hmm.. Have you tried putting "local" before food on line 1? local food = Instance.new("Part", game.workspace.foodlist)

0

it worked, thanks!

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