#How to optimize something without copy and pasting the same part with the same script

1 messages · Page 1 of 1 (latest)

bold bison
#

I have 3 checkpoints here, and was wondering how do I find a way to use only 1 script for all the checkpoints (theyre all using the same script btw)

raven thorn
#

you could probably use collectionservice for that

green turtle
#

collectionservice or just use tables

#

collectionservice does replicate though so that's generally not a good thing for trivial matters like this

bold bison
green turtle
#

Store them in a table and operate on them from within a loop

bold bison
#

also ive made an existing script

bold bison
gloomy badgeBOT
#

studio** You are now Level 7! **studio

bold bison
#

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

bold bison
#
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
green turtle
#

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

covert sage
# bold bison I have 3 checkpoints here, and was wondering how do I find a way to use only 1 s...

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:

  • Component refers to this module.
  • Component Class (e.g. MyComponent through this documentation) refers to a class created via Component.new
  • Component Instance refers to an instance of a component class.
  • `Roblox...
green turtle
covert sage
green turtle
#

figure it out yourself

covert sage
#

...

green turtle
#

please, you cannot expect me to spell it out for you twice