Is there any way of making a global kill script file using an Array, housing all the blocks kill scripts rather than having to put the script behind each block? Just thinking it would help with memory.
Thanks
Is there any way of making a global kill script file using an Array, housing all the blocks kill scripts rather than having to put the script behind each block? Just thinking it would help with memory.
Thanks
You could use a for loop and put the script in any parts that have a certain attribute.
for i, v in pairs(game:GetDescendants()) do
if v:GetAttribute("killbrick") then
local killbrickscript = script.Killbrick
killbrickscript.Parent = v
killbrickscript.Enabled = true
end
end
I’ve seen people use this for i,v in pairs, they added all the parts into a folder and renamed them with numbers. Would that be an easier way?
Both work, the one i gave would do it to every part with the killbrick attribute.
The kind you mentioned assumes you parent every killbrick in a folder which might not be the best choice but will still work.
It depends how many times the Touched event fires in each kill brick. (this is only my opinion, I may be completely wrong!)
2 scenarios:
A single player game with a whole bunch of killbricks and only the player as an unanchored object.
A game that has lots of killbricks and many players, with huge amounts of Unanchored Parts that could contact each killbrick.
So you think it would be easier to put it into each block I wanted as a killblock?
I don’t advise manually putting the same script in every killbrick incase you need to change something.
Use the for loop and see if that works for you.
You could also use CollectionService
for that
just in case if you want to learn more about it
I would use CollectionService for this
Open Tag Editor
Create a new tag
Put it into the parts
Run this script:
local CollectionService = game:GetService("CollectionService") --use the collection service
local killBricks = CollectionService:GetTagged("KillBrick") --get all instances with killbrick tag
for _, killBrick: BasePart in killBricks do --loop over the instances
killBrick.Touched:Connect(function(otherPart) --connect them to the touched event
local character = otherPart.Parent --get character
local humanoid = character:FindFirstChildOfClass("Humanoid") --find humanoid
if not humanoid then --if humanoid isn't found stop the script from killing
return
end
humanoid.Health = 0 --kill the character that stepped on the brick
end)
end
What a legend, thank you kindly sir. I’ve learnt something new today. I did always wonder what tags did but never played with them.
I found this way of doing it, a little less code too.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.