How can i make the function not run if not in the edit mode of studio?

Basically what i want to make is a way the plugin doesnt call the function when a object get added by testing mode so peoples can sandbox to see if the plugin did the job at putting they game safe.

Attempted:

  • Multiple Run Service Checks
local Running

workspace.DescendantAdded:Connect(function(des)
	Running = function()
		if not RunService:IsStudio() then
			return false
		end 

		if not RunService:IsClient() then
			return false
		end

		if not RunService:IsServer() then
			return false
		end

		if not RunService:IsEdit() then
			return false
		end

		if RunService:IsRunMode() then
			return false
		end

		-- Running in edit mode
		return true
	end

	if Running then
		ChangeHistoryService:SetWaypoint("Analysing the new object")
		AnalyseObject(des)
	end
end)

Try something like this, hopefully it works out…

local RunService = game:GetService("RunService")
local ChangeHistoryService = game:GetService("ChangeHistoryService")

workspace.DescendantAdded:Connect(function(des)
    local Running = function()
        if not RunService:IsStudio() then
            return false
        end 

        if not RunService:IsClient() and not RunService:IsServer() then
            return false
        end

        if RunService:IsRunMode() then
            return false
        end

       -- edit mode: true
        return true
    end

    -- correct mode: true
    if Running() then
        ChangeHistoryService:SetWaypoint("Analysing the new object")
        AnalyseObject(des)
    end
end)

Thanks it actually fixed the issue with my plugin, it help me a lot to make a quicker release.

1 Like

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