local function ApplyTemplate(Script: Instance)
if game:GetService("RunService"):IsRunning() then
return
end
task.wait(1)
print(Script.Name)
if Script.Name ~= "Script" and Script.Name ~= "ModuleScript" and Script.Name ~= "LocalScript" then
return
end
--... more code, unrelated.
end
game.DescendantAdded:Connect(ApplyTemplate)
Hello everyone!
On this line here:
if Script.Name ~= "Script" and Script.Name ~= "ModuleScript" and Script.Name ~= "LocalScript" then
return
end
The script doesn’t return it. This is in a LocalScript [For a plugin]. The script print’s the correct name of the script, e.g “DataController”, but it never returns. Does anyone have any idea why?
I am trying to make a plugin for myself that does something to a script, but I cannot get passed this.
Any support will be appreciated, thanks. Been working for 30 minutes trying to fix this issue
“Script” is passed through via game.DescendantAdded, and I’m not trying to refer to the current script that the code is in, I’m trying to refer to the new instance added.
Also the code is part of a larger project which I don’t want to say
local function ApplyTemplate(Object: Instance)
if game:GetService("RunService"):IsRunning() then
return
end
task.wait(1)
print(Object.Name)
if Object.Name ~= "Script" and Object.Name ~= "ModuleScript" and Object.Name ~= "LocalScript" then
return
end
if Object:IsA("Script") then
if Object.Source == "" then
Object.Source = [[
]]
end
elseif Object:IsA("ModuleScript") then
Object.Source = [[
]]
elseif Object:IsA("LocalScript") then
Object.Source = [[
]]
end
end
Maybe this helps provide context on what I want to do? I don’t want it to return if it’s not a Script, but I want it to return if the Script already has a name, because that likely means it already has code inside, and it shouldn’t replace said code.
I have found the cause, previously I never added that if statement in, so I didn’t realise it, but every script just contains that code now, so that’s my fault.
The if statement does return, but the code is just bugged, whoops.
Type of returns the data type (instance, boolean, number, string, table, etc…). typeof(Instance.new("Part")) → "Instance" Instance.new("Part").ClassName → "Part"