#Setting up another script inside a script

61 messages · Page 1 of 1 (latest)

sullen epoch
#

I have this script inside a part:

`script.Parent.ClickDetector.MaxActivationDistance = 7
local script = script
script.Parent.ClickDetector.MouseClick:Connect(function(abc)
local newpart = Instance.new("Part",workspace)
newpart.Material = Enum.Material.Neon
local randomColor = math.random(1, 2)
if randomColor == 1 then
newpart.BrickColor = BrickColor.new("Bright blue")
else
newpart.BrickColor = BrickColor.new("Really red")
end
newpart.Size = Vector3.new(4,4,4)
newpart.Position = Vector3.new(math.random(1,30),4,math.random(1,30))
newpart.Anchored = false
local clickdetector = Instance.new("ClickDetector",newpart)
local newscript = Instance.new("Script",newpart)
-- Set the source of the new script
local source = script.Source
newscript.Source = source

end)`

The script is supposed to spawn a new part in a random location when clicked on the part.

Everything is going well, the Click detector is working well but what is causing the truble is this part of the script:

local newscript = Instance.new("Script",newpart) -- Set the source of the new script local source = script.Source newscript.Source = source

It is supposed to make a new script inside the newpart, the source of the script should be the same as the orignal part, but the script is being created and the source inside the newscript is empty.

warm meteorBOT
#

studio** You are now Level 4! **studio

sullen epoch
#

Yo i am also getting this error

#

The current thread cannot write 'Source' (lacking capability Plugin)

bright canyon
#

script.parent

#

local newscript = Instance.new("Script",newpart)
-- Set the source of the new script
local source = script.Source
newscript.Source = source

sullen epoch
sullen epoch
#

script.parent is the part

bright canyon
#
script.Parent.ClickDetector.MaxActivationDistance = 7
local script = script
script.Parent.ClickDetector.MouseClick:Connect(function(abc)
    local newpart = Instance.new("Part",workspace)
    newpart.Material = Enum.Material.Neon
    newpart.parent = workspace

    local randomColor = math.random(1, 2)
    if randomColor == 1 then
        newpart.BrickColor = BrickColor.new("Bright blue")
    else
        newpart.BrickColor = BrickColor.new("Really red")
    end
    newpart.Size = Vector3.new(4,4,4)
    newpart.Position = Vector3.new(math.random(1,30),4,math.random(1,30))
    newpart.Anchored = false
    local clickdetector = Instance.new("ClickDetector",newpart)
    local newscript = Instance.new("Script",newpart)
    -- Set the source of the new script
    local source = script.Source
    newscript.Source = source
    
end)
#

newscript.parent = workspace

#

sorry

#

or maybe just put the newscript parent

#

idk what you want to put

sullen epoch
bright canyon
#

but it need a parent

#

then

sullen epoch
bright canyon
#

newscript.parent = newpart

#

done.

sullen epoch
#

here
local newscript = Instance.new("Script",newpart)

The newscripts parent is newpart

#

local newscript = Instance.new("Script",newpart)

#

the 2nd parameter sets up the parent

bright canyon
#

oh i didnt see that

#

but the script you use earliear wont work

#

cuz newscript put in newpart that dont have a parent

#

xd

sullen epoch
bright canyon
#

you made this using ai?

sullen epoch
#

i am new though

bright canyon
#

nah man

#

i didnt think you use script.source

#

idk man but here an idea

#

clone the script after the newpart is made

sullen epoch
#

but smth wrong with my scrpt

bright canyon
#

and the clone script put into the newpart

#

done.

#

idk if that work

#

but with logic i think it will

sullen epoch
sullen epoch
bright canyon
#

idk man

#

just try

#

i never experience this type of problem

grand ocean
sullen epoch
#

ya u can, there is a clone() in object browser in scripts

#

but idk how to use it, like how do i tell where to clone it

bright canyon
#

uh

#

let me remake the script

grand ocean
#
local scriptToClone = (...)--Direction to script ex. ReplicatedStorage

local sciptClone = scriptToClone:Clone()
scriptClone.Parent = (...) -- where u want the script
#

something similar to that

bright canyon
#
script.Parent.ClickDetector.MaxActivationDistance = 7
local script = script
script.Parent.ClickDetector.MouseClick:Connect(function(abc)
    local newpart = script.parent:Clone()
    newpart.Parent = workspace
    newpart.Material = Enum.Material.Neon
    local randomColor = math.random(1, 2)
    if randomColor == 1 then
        newpart.BrickColor = BrickColor.new("Bright blue")
    else
        newpart.BrickColor = BrickColor.new("Really red")
    end
    newpart.Size = Vector3.new(4,4,4)
    newpart.Position = Vector3.new(math.random(1,30),4,math.random(1,30))
    newpart.Anchored = false
    -- Set the source of the new script



    
end)```
bright canyon
#

there u go

#

it clone the whole part

sullen epoch
bright canyon
#

the script u use is unefficent

sullen epoch
#

bro thankuuu soo muchh dude it workss