Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Character dies on touch?

Asked by 6 years ago

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

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

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?

0
That still kills the character ApesNotMonkeyz 4 — 6y
0
It also makes the parts stack on top of each other ApesNotMonkeyz 4 — 6y
0
Whoops, I accidentally put "hit" on line 5. I've edited it now. Does it work or does it still kill the character? UgOsMiLy 1074 — 6y
0
Nope nothing happens ApesNotMonkeyz 4 — 6y
View all comments (4 more)
0
It dosent kill the character tho ApesNotMonkeyz 4 — 6y
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 ApesNotMonkeyz 4 — 6y
0
Hmm.. Have you tried putting "local" before food on line 1? local food = Instance.new("Part", game.workspace.foodlist) UgOsMiLy 1074 — 6y
0
it worked, thanks! ApesNotMonkeyz 4 — 6y
Ad

Answer this question