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

How would I make a listening function to all the parts in a model?

So I have got code already, which buys a part. But I want to introduce tables, so I've added a table. But I now need a listening function for everything in a model, so I can replace workspace.dropTwoBuy. Any ideas?

Prices = {5}
Buyables = {game.ServerStorage.Giver2}

workspace.dropTwoBuy.Head.Touched:connect(function(x)
	if x.Parent.Name == owner and game.Players[owner].leaderstats.Points.Value == 5 then
		y = game.ServerStorage.Giver2:Clone()	
		y.Parent = workspace
		wait(1)
		

		workspace.dropTwoBuy:Destroy()
		
	end
end)

2 answers

You could do a generic for loop, and listen on each instance that way.

model = workspace.Model

for _, part in pairs(model:GetChildren()) do
part.Touched:connect(function()
part.BrickColor = BrickColor.Blue()
end)
end

Sorry I can't tab on mobile.

Prices = {5}
Buyables = {game.ServerStorage.Giver2}

workspace.dropTwoBuy.Head.Touched:connect(function(x)
	if x.Parent.Name == owner and game.Players[owner].leaderstats.Points.Value == 5 then
		y = game.ServerStorage.Giver2:Clone()
		b = workspace.Reciever
		b.Size = Vector3.new(14, 2, 4.8)	
		y.Parent = workspace
		wait(1)
		b.Position = Vector3.new(37.1, 1, -12)
		

		workspace.dropTwoBuy:Destroy()
		
	end
end)

1 comment

0

There's an 'edit' button you can use for that.

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