I have a script in my game that resets all the parts after it is triggered. Here is the code:
function ClearGame() --Clear the game parts
local GameParts = SerStore:FindFirstChild("GameParts"):GetChildren()
local CurrentParts = workspace:GetChildren()
for i, part in pairs(CurrentParts) do
if part:IsA("BasePart") or part:IsA("Model") or part:IsA("UnionOperation") then --Check to see if it's the three base parts
if part.Name ~= "Terrain" then --Make sure it's not terrain
if not part:FindFirstChild("Humanoid") then --Make sure it's not the player
part:Destroy()
end
end
end
end
for i, part in pairs(GameParts) do --clone and parent the serstore parts
local ClonedPart = part:Clone()
ClonedPart.Parent = workspace
end
end
Here’s the problem: After this function is called, NONE of the other server scripts work. Does anyone have any idea to as how to fix this? Any and all help is appreciated, and happy holidays!
We can’t help much without having an idea of what the other scripts do. My best guess with what you’ve shown here, is that your other scripts may be using old references of objects that have been deleted. After you’ve cloned models and parented to workspace, are you reassigning any references in other scripts that may have depended on the original deleted models/parts?
I see what you mean. I am not reassigning them, and that’s why the scripts aren’t working. Do you know how I would fix this.
Here’s one of scripts for some context:
function MovingParts()
local TweenService = game:GetService("TweenService") --Services
local RepStore = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local function Base(Model, PrimaryPart, GoalsIn, GoalsOut)
local ClickDetect = Model:FindFirstChild("ClickDetector") --Basic Vars
local IsOpened = Model:FindFirstChild("IsOpened")
local HoverVl = RepStore.HoverVls:FindFirstChild("HoverVl")
local Info = TweenInfo.new( --Info for tween
.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0)
local function tweens() --Check if its opened
if IsOpened.Value ~= true then
local OutTween = TweenService:Create(PrimaryPart, Info, GoalsOut)--Play Going out tween
OutTween:Play()
IsOpened.Value = true
HoverVl.Value = "Close" --Have to update hovervl from here
else
local InTween = TweenService:Create(PrimaryPart, Info, GoalsIn)--Play going in Tween
InTween:Play()
IsOpened.Value = false
HoverVl.Value = "Open"
end
end
ClickDetect.MouseClick:Connect(function()
tweens()
end)
end
local function Drawer1() --Drawer1Function
local Drawer1Mod = game.Workspace:FindFirstChild("Drawer1Mod")
local Drawer1 = Drawer1Mod:FindFirstChild("Drawer1")
local GoalsIn = {CFrame = Drawer1.CFrame * CFrame.new(0, 0, 0)} --Goals going back in
local GoalsOut = {CFrame = Drawer1.CFrame * CFrame.new(0, 0, -2.5)} --Goals going back out
Base(Drawer1Mod, Drawer1, GoalsIn, GoalsOut)
end
local function Drawer2() --Drawer2 function
local Drawer2Mod = game.Workspace:FindFirstChild("Drawer2Mod")
local Drawer2 = Drawer2Mod:FindFirstChild("Drawer2")
local GoalsIn = {CFrame = Drawer2.CFrame * CFrame.new(0, 0, 0)} --Goals going back in
local GoalsOut = {CFrame = Drawer2.CFrame * CFrame.new(0, 0, -2.5)} --Goals going back out
Base(Drawer2Mod, Drawer2, GoalsIn, GoalsOut)
end
local function Window()
local WindowMod = game.Workspace:FindFirstChild("Window") --Window Function
local PrimaryPart = WindowMod:FindFirstChild("RootPart")
local GoalsIn = {CFrame = PrimaryPart.CFrame * CFrame.new(0, -0, 0)} --Goals going back in
local GoalsOut = {CFrame = PrimaryPart.CFrame * CFrame.new(0, 4, 0)} --Goals going back out
Base(WindowMod, PrimaryPart,GoalsIn, GoalsOut)
end
Drawer1()
Drawer2()
Window()
end
MovingParts()
Fire a bindable event when you delete all the parts/models from the workspace, then remake any object references/connections when the bindable event is fired.