I have a tool where it clones itself. I want to run this script itself(not function inside or chunks, but script itself) but it seems i cant find a way to. When i searched for it, I found a method called dofile()
but it won`t work… Is there any way to do this? Also, is there a way not to make the script run when not needed, like it only runs when it is called.
(The code below is what i kind of want to do)
script1:
1 | if --[[tool--]] .Parent ~ = game.Workspace then |
2 | --call the script2 |
3 | end |
script2:
1 | local toolClone = script.Parent:Clone() |
2 | toolClone.Name = "toolClone" |
3 | toolClone.Parent = game.Workspace --makes appear the tool to game, since it was in serverStorage |
ModuleScripts will not run automatically.
Aso, a bindable function might work for you.
`````` if [[--tool--]] ~= game.Workspace then
script.Parent:Fire()
end ``````
Script#2
game.Workspace.Event.Event:Connect(function()
local toolClone = script.Parent:Clone() --Not sure why you'd want to clone the script, but okay.
toolClone.Name = "toolClone"
toolClone.Parent = game.Workspace
end)
Probably the easiest way to do that, would to set the script to disabled and have the script controlling it to set it to
1 | disabled = false |
for instance in your case we would use:
1 | if [[--tool--]] ~ = game.Workspace then |
2 | script.Parent.Disabled = false |
end