saassadsdaHello I would like to know, ideas?
Heya, I think you’re talking about functions, here’s an example:
local function Move(Pos)
script.Parent.CFrame = Pos
end
local Pos = CFrame.new(0,0,0)
Move(Pos)
Uhm I don’t know, I have a Parkour game, where there are traps, and the thing is that I have more than 3000 traps and each trap has a script, so I want to see how to avoid putting 3000 trap scripts on just one But do the same, that is, a single script will give the function to the 3000 pieces that if you touch it it kills you.
Ah if that’s so, why don’t you detect when the player touches a trap instead of detecting when traps touch a player? Like that you can just have 1 script for the player.
What? I’m looking for a script that will order 3000 pieces if a player touches it dies, I don’t know if it will make me understand.
Sorry but if it’s not the last thing I said, then I don’t know what you mean by that. What do you mean with “order”?
It’s that I didn’t understand you either, maybe the translator is changing what you say, since I speak Spanish and I don’t know English
Ah. Okay. Make a script for the player that detects if that player touches a trap. Like that you will only have 1 script instead of 3k.
Yes, but that is exactly what I am asking since I don’t know how to create the script
I am asking how to create the script
Take a look at the documentation for the CollectionService:
https://developer.roblox.com/en-us/api-reference/class/CollectionService
Also, when you’ve read that, this may also be useful:
Basically, using CollectionService & the Tag Editor plugin, you can assign each part that kills the player the same tag and when the parts with that tag are touched, kill the player in one script.
Are you asking how to make a script through a script?
You can use CollectionService or use a for loop(not reccomended with a lot of parts) to do it
I want to see how to make a script that makes certain blocks give the order if the player touches it dies. This way I don’t have to put a script in each piece, and not be repeating them.
try this
local CS = game:GetService("CollectionService")
local Tagged = CS:GetTagged("TagName")
for _,tag in pairs(Tagged) do
tag.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(hum.MaxHealth)
end
end)
end
Or you can use a for loop as shown below
You will have to use the .Touched
event on each part. You can put the parts in a folder, and run a loop through all the parts. Here is an example:
local parts = workspace.DeadlyParts
for _, part in pairs(parts:GetChildren()) do
part.Touched:Connect(function(hit)
-- code here
end)
end