You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want it to after the frame has been destroyed it well let you clone another frame -
What is the issue? Include screenshots / videos if possible!
I’m trying to make it where when you click the part in it will clone the frame in if you click it again it won’t add another one until that one is destroyed but when I add the part on my mop server script it breaks my mop server script in it will not do anything
Hers my part that clones the frame script
local ClickDetector = script.Parent.ClickDetector
local Door = game.Workspace.Door13
local Players = game:GetService("Players")
local FrameManager = require(game.ReplicatedStorage.FrameManager)
local teleportLocations = {
Floor1 = Vector3.new(13.789, 37.27, 52.203),
}
local function teleportToFloor(player, floor)
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
character.HumanoidRootPart.CFrame = CFrame.new(teleportLocations[floor])
end
end
local function destroyFrame(player)
local mainFrame = player.PlayerGui:WaitForChild("MainFrame")
local jobFrame = mainFrame:WaitForChild("StartFrame"):WaitForChild("JobsHolder"):WaitForChild("ScrollingFrame"):FindFirstChild("Job")
if jobFrame then
jobFrame:Destroy()
FrameManager:setFrameExists(player, false)
end
end
ClickDetector.MouseClick:Connect(function(player)
if FrameManager:getFrameExists(player) then
return
end
local mainFrame = player.PlayerGui:WaitForChild("MainFrame")
local jobFrame = mainFrame:WaitForChild("StartFrame"):WaitForChild("JobsHolder"):WaitForChild("ScrollingFrame"):WaitForChild("Job")
local newJobFrame = jobFrame:Clone()
newJobFrame.Parent = jobFrame.Parent -- Set the parent to the ScrollingFrame
newJobFrame.Visible = true
newJobFrame.Username.Text = player.Name
newJobFrame.Room.Text = Door.Roomnumber.Value
FrameManager:setFrameExists(player, true)
local teleportButton = newJobFrame:WaitForChild("Teleport")
teleportButton.MouseButton1Click:Connect(function()
teleportToFloor(player, "Floor1")
destroyFrame(player)
end)
end)
Here is my mop server script
local TweenService = game:GetService("TweenService")
local SpillLocationsFolder = game.Workspace.SpillLocations
local SpillLocations = SpillLocationsFolder:GetChildren()
local FrameManager = require(game.ReplicatedStorage.FrameManager)
local function DestroyFrame(player)
local success, errorMessage = pcall(function()
local mainFrame = player.PlayerGui:WaitForChild("MainFrame", 5)
if not mainFrame then
warn("MainFrame not found for player: " .. player.Name)
return
end
local startFrame = mainFrame:WaitForChild("StartFrame", 5)
local jobsHolder = startFrame:WaitForChild("JobsHolder", 5)
local scrollingFrame = jobsHolder:WaitForChild("ScrollingFrame", 5)
for _, frame in pairs(scrollingFrame:GetChildren()) do
if frame:IsA("Frame") and frame.Name == "Job" and frame.Visible then
frame:Destroy()
FrameManager:setFrameExists(player, false)
print("Destroyed frame for player: " .. player.Name)
break
end
end
end)
if not success then
warn("Error in DestroyFrame: " .. errorMessage)
end
end
for i = 1, #SpillLocations do
local Spill = SpillLocations[i]
local MopSpillEvent = Spill.MopSpill
MopSpillEvent.OnServerEvent:Connect(function(Player)
print("Cleaning Spill")
local Tween = TweenService:Create(Spill, TweenInfo.new(5), {Size = Vector3.new(0, 0, 0)})
Tween:Play()
wait(5)
Spill.Transparency = 1
Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 1
print("Stopped code, destroying frame")
DestroyFrame(Player)
end)
end
while true do
local RandomSpill = SpillLocations[math.random(1, #SpillLocations)]
RandomSpill.Transparency = 0
RandomSpill.BrickColor = BrickColor.Random()
RandomSpill.Size = Vector3.new(0.1, 4.4, 4.65)
wait(60)
end
and hers my FrameManager modulescript
local FrameManager = {}
FrameManager.frameExists = {}
function FrameManager:setFrameExists(player, exists)
self.frameExists[player.UserId] = exists
end
function FrameManager:getFrameExists(player)
return self.frameExists[player.UserId] or false
end
return FrameManager