Yes. There is. I will give a specific example. If it does not apply to what you want, oh well.
Say you have multiple parts and you want them to be able to be clicked. So you use ClickDetector.MouseClick. When they are clicked, they give you points.
local coins = script.Parent
coin.MouseClick:Connect(function(player)
player.Coins.Value = player.Coins.Value + 1
end)
This is the same script you have for your 40+ coins. But say later on you decide you want to double how many coins they get based on if they have a coin doubler tool in their backpack.
So you want to check if they have that tool.
coin.MouseClick:Connect(function(player)
local coins_to_add = player.Backpack:FindFirstChild("CoinDoubler") and 2 or 1
player.Coins.Value = player.Coins.Value + coins_to_add
end)
But you have to change that code for all 40+ scripts with this!
What you can (and should) do, is instead put it in the model of coins in the coins model itself with all the coins and change to a for loop:
local function on_mouse_click(player)
local coins_to_add = player.Backpack:FindFirstChild("CoinDoubler") and 2 or 1
player.Coins.Value = player.Coins.Value + coins_to_add
end
for _, child in ipairs(game:GetService("Workspace").Coins:GetChildren()) do
if child.Name == "Coin" then
child.ClickDetector.MouseClick:Connect(on_mouse_click)
end
end
1 comment
Oh, so just like this. Well, not what I expected but if it's just it then guess it is. I also found uploading a module script and then loading it from ID a useful workflow but this sounds like not a bad solution too. Tnx!