Local script wont work after model gets regenerated

This is a local script that moves a model:

local vehicle = game.Workspace.Robbery.SubmarineExterior

game:GetService("RunService").Heartbeat:Connect(function(dt)

	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0,0  * dt))
	wait(5)
	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0.05,0  * dt))
	wait(5)
	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1,0,0  * dt))
	end)

and this is a server script that regenerates the model:

    object = script.Parent

    if (object ~= nil) and (object ~= game.Workspace) then

    model = object

    backup = model:clone()

    waitTime = script.Parent.Time.Value

    wait(1)

    while true do

    wait(waitTime+2)

    model:remove()

    model = backup:clone()

    wait(2)

    model.Parent = game.Workspace

    model:makeJoints()

    end

    end

The problem is whenever the first regenerate happens the local script dosent work!

in the server script, you want to disable the LocalScript before removing the model

make a new line above the model:remove() and add
local LocalScript = and put in the location of your LocalScript here
then make a new line below it and add
LocalScript.Disabled = true

make a line below model:makeJoints() and add:
LocalScript.Disabled = false

Are you having any errors pop up? or is it a logic error? If any errors pop up then please show us, also have you done any checks at all to see where the issues is? E.G Print statements to find out exactly where the issue is stemming from.

i think its because the local script cant find the new model and theres no error pops up!
do u have any solution?

1 Like

wont work 30 characters…