Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

What causes a script to not work after it is cloned?

Asked by 5 years ago
Edited 5 years ago

Original works until it is the model is cloned.


--give cookie tray (put in inven, remove cookie tray, turn off oven script.Parent.ClickDetector.MouseClick:connect(function(player) local foodinventory = player:FindFirstChild("BakedGoods") if foodinventory ~= nil then print("yes") local alreadyexists = foodinventory:FindFirstChild("ChocChipCookies") if alreadyexists == nil then print("yeet") local tag = Instance.new("NumberValue",foodinventory) tag.Name = "ChocChipCookies" tag.Value = tag.Value + 12 else print("yoot") alreadyexists.Value = alreadyexists.Value + 12 --instead of making a new value, adds 12 to existing inventory value end end workspace.Oven1.On.Value = false --turn off oven (will make oven w/player id tag attached later) script.Parent.Parent:remove() end)
0
It doesn't work for me either, but what if you have the model cloned and pasted BEFORE the script breaks? Still doesn't work Cvieyra2test 176 — 5y
1
Use :Connect() and :Destroy() LoganboyInCO 150 — 5y
1
:remove() is domesticated :destroy(). also, :Connect() is :connect() but capitalized. Fifkee 2017 — 5y
2
remove() isn't a pet @Fifkee, so it can't be domesticated DeceptiveCaster 3761 — 5y
View all comments (2 more)
0
LOL WideSteal321 773 — 5y
0
*laughs* GamingZacharyC 152 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Try this, if you disable the script before it is cloned, then enable it once it's in the Workspace, then it will work normally. Here is my example: Script within a Part, within a Model, within Workspace

-- give cookie tray, put in Oven, remove cookie tray, turn off oven
script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local foodinventory = player:FindFirstChild("BakedGoods")
    if foodinventory ~= nil then
        print("yes")
        local alreadyexists = foodinventory:FindFirstChild("ChocChipCookies")
        if alreadyexists == nil then
            print("yeet")
            local tag = Instance.new("NumberValue", foodinventory)
            tag.Name = "ChocChipCookies"
            tag.Value = tag.Value + 12     
        else
            print("yoot")
            alreadyexists.Value = alreadyexists.Value + 12  --instead of making a new value, adds 12 to existing inventory value
        end
    end

    workspace.Oven1.On.Value = false --turn off oven (will make oven w/player id tag attached later)
    script.Parent.Parent:Destroy()
end)

I changed a few of the connections, for instance, remove is deprecated, and connect is now Connect. Script within ServerScriptService

while true do
    local model = workspace:FindFirstChild("Cook")
    if model == nil then
        local model2 = game.ServerStorage.Cook:Clone()
        model2.Parent = workspace
        model2.Part.Script.Disabled = false -- this is the location of the script with the above function
    end
    wait()
end

This doesn't have to be a continuous loop, but I used one to test that it works. You need to make sure that the script is disabled normally when in studio (since the function will enable it)

Ad

Answer this question