#How to optimize something without copy and pasting the same part with the same script
1 messages · Page 1 of 1 (latest)
you could probably use collectionservice for that
collectionservice or just use tables
collectionservice does replicate though so that's generally not a good thing for trivial matters like this
what do you mean by using tables?
Store them in a table and operate on them from within a loop
also ive made an existing script
the script contains script.Parent.Touched and now i moved it to SSS
** You are now Level 7! **
the thing is now script.Parent is just the serverscriptservice
and the script dosent work
and i cant just do Getchildren:("Part") because the parts all have different number values
is there a way to fix this problem?
local CollectionService = game:GetService("CollectionService")
for _, part in CollectionService:GetTagged("Checkpoint") do
local Players = game:GetService("Players")
local db = true
Players.PlayerAdded:Connect(function(plr)
script.Parent.Touched:Connect(function(plr)
if db then
db = false
local player = game.Players:FindFirstChild(plr.Parent.Name)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats.Stage.Value < tonumber(script.Parent.Name) then
leaderstats.Stage.Value = tonumber(script.Parent.Name)
end
db = true
end
end)
end)
end
massive memory leak, collectionservice (auto replication) unnecessary
and :GetChildren() will return a table of all children of an instance
it does not matter what name it is
You should just use component utility by sleitnick (same as collection service ) https://sleitnick.github.io/RbxUtil/api/Component/
Bind components to Roblox instances using the Component class and CollectionService tags.
To avoid confusion of terms:
Componentrefers to this module.Component Class(e.g.MyComponentthrough this documentation) refers to a class created viaComponent.newComponent Instancerefers to an instance of a component class.- `Roblox...
"yes let's bloat our game with overhead made by someone else and make it harder for us to learn important concepts, yeeeess that's a great idea! Why didn't I think of that?"
What was the point of saying that?
figure it out yourself
...
please, you cannot expect me to spell it out for you twice