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)
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)