How do I detect if the user stops editing the experience?

  1. What do you want to achieve? I am working in a plugin where the camera follows the player, like Camera Light, I want to make the part destroyed when the user stops editing the experience.

  2. What is the issue? It will stay if you stop working on the experience

  3. What solutions have you tried so far? There is nothing in the DevForums

here’s the code

local toolbar = plugin:CreateToolbar("CamLight")

local button = toolbar:CreateButton("CamLight", "", "rbxassetid://12942501521")

local active = false

local part, light

button.Click:Connect(function()
	active = not active
	part = Instance.new("Part")
	light = Instance.new("PointLight", part)
	if active then
		part.Parent = workspace
		part.Size = Vector3.new(0.001, 0.001, 0.001)
		part.Parent = workspace
		part.Name = "CamPart"
		part.Locked = true
		
		--// Light //--
		light.Brightness = 1
		light.Range = 60
		light.Color = Color3.new(1, 1, 1)
		light.Name = "CamLight"
		light.Shadows = true

		while active do
			part:PivotTo(require(script:WaitForChild("Camera")).CFrame)
			task.wait()
		end
	else
		if workspace:WaitForChild("CamPart") then
			workspace.CamPart:Destroy()
		end
	end
end)

I want to make a plugin like Camera Light (don’t worry I’m not publishing it to the marketplace), and I don’t know how to detect if the user stops editing the game.

Haven’t tried this myself, but maybe you can check with the playerRemoving event since a player instance is created when you enter studio and exit.
image

uuhh that only applies to team create, I want it to work without team create

maybe this
RunService:IsEdit()

You could just set the the Archivable property to false on every instance the plugin makes and then they won’t be saved

still not working

crashed studio when I did it

It shouldn’t have crashed studio its a pretty standard thing. you can even change it from the property window.

you just add to the created part instance and it will not longer save.

part.Archivable = false
local toolbar = plugin:CreateToolbar("CamLight")

local button = toolbar:CreateButton("CamLight", "", "rbxassetid://12942501521")

local active = false

local part, light

button.Click:Connect(function()
	active = not active
	part = Instance.new("Part")
	light = Instance.new("PointLight", part)
	if active then
		part.Parent = workspace
		part.Archivable = false
		part.Size = Vector3.new(0.001, 0.001, 0.001)
		part.Parent = workspace
		part.Name = "CamPart"
		part.Locked = true
		
		--// Light //--
		light.Brightness = 1
		light.Range = 60
		light.Color = Color3.new(1, 1, 1)
		light.Name = "CamLight"
		light.Shadows = true

		while active do
			part:PivotTo(require(script:WaitForChild("Camera")).CFrame)
			task.wait()
		end
	else
		if part then
			part:Destroy()
		end
	end
end)

You might wanna check the “camera” module or whatever it is. Also you might wanna make sure the camera module actually exists.

that camera module allows you to get the camera when you require it

I was so dumb, I put the task.wait() in the wrong place, I tried it and still didn’t work

Not sure what’s going wrong,maybe I’m misunderstanding so I’ve just rewrote it.

local RunService = game:GetService('RunService')
local toolbar = plugin:CreateToolbar("CamLight")
local button = toolbar:CreateButton("CamLight", "", "rbxassetid://12942501521")

local renderConnection = nil

local Camera = game.Workspace.CurrentCamera

local camPart = Instance.new('Part')
camPart.Size = Vector3.new(.001,.001,.001)
camPart.Name = 'CamPart'
camPart.Transparency = 1
camPart.CanQuery = false
camPart.Locked = true
camPart.Anchored = true
camPart.Archivable = false
local pointLight = Instance.new('PointLight')
pointLight.Brightness = 1
pointLight.Range = 60
pointLight.Color = Color3.new(1,1,1)
pointLight.Name = 'CamLight'
pointLight.Shadows = true
pointLight.Parent = camPart

button.Click:Connect(function()
	if renderConnection then
		renderConnection:Disconnect()
		renderConnection = nil
		camPart.Parent = nil
	else
		renderConnection = RunService.RenderStepped:Connect(function() 
			camPart.CFrame = Camera.CFrame
		end)
		camPart.Parent = Camera
	end
end)

Use this as you like, take a look through maybe you can see what is going wrong with your version

1 Like

the plugin script isn’t in a local script

Doesn’t need to be, Plugins can use localscript variables.

1 Like

oh nevermind, I thought it only accesses server script stuff and plugin variables.

I want roblox to add pluginscripts

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.