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

How to script items that are grouped?

Asked by 7 years ago
Edited 7 years ago

I have two scripts they each look like this:

"function onTouched(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local DarkGreen = workspace.DarkGreen DarkGreen:Destroy() end end

script.Parent.Touched:connect(onTouched)" but I want them to work on grouped parts not separately. How do I do this or can I?

2 answers

Log in to vote
2
Answered by
Sur4y 40
7 years ago
Edited 7 years ago

Hello there!

First off, use code blocks, they really help.

And about your problem. From what I've understood, I see that you are trying to trigger a function whenever a player touches a model. If that is the case, you can use for i,v in pairs.

So it'd be like :

for i,v in pairs(your model's location here, for example, game.Workspace.Model:GetChildren()) do
--So we used :GetChildren() function which gets the children of a parent if the parent has any children.
--Now, we are going to do:
    v.Touched:connect(function()
        --Your code here
    end)
end

If I got it wrong, you can tell me what's the case. I didn't really understand much because your text seems unorganized.

So, overall, we used "v" as of the children of the model inside workspace. If we want to do something to the children of the model, we use v.

Then you can do anything with you want. For example:

v.Touched:connect(function(hit)
    print(hit.Name)
end

So what this does is, whenever something touches the model, it prints it's name.

0
Did it help you? Sur4y 40 — 7y
0
Can you tag my answer as "answered" :p Sur4y 40 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

I think I get it thank you :) I will play around with that for a bit and see where it goes and I will be sure to organize my questions better in the future thank you xD the destruction of grouped parts will be done >: ) muahahaha

0
Tag Surays post as answered :) FrostTaco 90 — 7y

Answer this question