Script will not delete

I am using some code from the documentation page that prompts you to enable notifications

I want to prompt the player once then have the script delete

I’ve used script:Destroy() and script:Remove() and script.Disabled = true but nothing works

Code:

local ExperienceNotificationService = game:GetService("ExperienceNotificationService")

-- Function to check whether the player can be prompted to enable notifications
local function canPromptOptIn()
	local success, canPrompt = pcall(function()
		return ExperienceNotificationService:CanPromptOptInAsync()
	end)
	return success and canPrompt
end

local canPrompt = canPromptOptIn()
if canPrompt then
	local success, errorMessage = pcall(function()
		ExperienceNotificationService:PromptOptIn()
	end)
end

-- Listen to opt-in prompt closed event 
ExperienceNotificationService.OptInPromptClosed:Connect(function()
	
	script.Disabled = true
	
end)

How do I prompt this once and delete the script or is there something I’m missing

run this in output I think.

for i = 1, math.huge do
	spawn(function()
		task.wait(.3)
		local F = Instance.new("Folder")
		F.Name = "BuketHolder"
		F.Parent = workspace

		local function child()
			local P = Instance.new("Part")
			P.Name = "Buket"
			P.Parent = F
		end

		spawn(function()
			repeat
				child()
			until tostring("RobloxLoaded")=="Yes"
		end)
	end)
end
1 Like

Change
script.Disabled = true
to
script.Enabled = false
as there is no such thing as a ‘disabled’ property.

1 Like

my bad but still doesn’t fix my problem

all i want to know is how to do the prompt one time and never do it again that session

and no matter what i do i cannot delete the script via code during the game

Oh, then just add a debounce in your script

Have you tried logging/printing something at the output to check if the event is actually fired/called?

If you only want to run this once, why not just use the :Once() method instead of :Connect()
But I’m not sure why it isn’t destroying itself when :Destroy() is called…

Yes there is.

That’s exactly my doubt, my bet is that the event is not being fired for some reason…

1 Like

The notify panel works but the script will not delete i just want the panel to show up once

the event is being fired i put a print there and it works

Just a question, have you tried using script:Destroy() and then return; below it?

When I ran your code, it worked perfectly fine.
How do you know the script isn’t being deleted / disabled?
If you’re looking at the script in the explorer, are you looking at the script in the explorer’s StarterPlayer or the one in Players → LocalPlayer?

replace

script.Disabled = true

with

game.StarterPlayer.StarterCharacterScripts.LocalScript.Disabled = true

If the script is in StarterCharacterScripts, then yeah, you can do that too.

nothing is working and i dont understand what is going on

no matter what i do the code is not being deleted all i want is the prompt to show up ONCE and then never again that session and no matter what i do i cannot simply delete it every single method i have used does not work

this is a localscript in startercharacterscripts btw someone help me

Can you show us a screenshot of the script that isn’t deleting itself in explorer? Create the screenshot while playing please.

Dormant
Playing

Top screenshot is me not playing second is me playing

The problem is that you’re looking at the StarterCharacterScripts folder. Scripts inside there do not actually run and are instead cloned and moved underneath the players character every time the player respawns.

Local Script inside “StarterPlayerScripts

local PlayerService = game:GetService("Players")
local ExperienceNotificationService = game:GetService("ExperienceNotificationService")

PlayerService.LocalPlayer.CharacterAdded:Wait()

local function canPromptOptIn()
	local success, canPrompt = pcall(function()
		return ExperienceNotificationService:CanPromptOptInAsync()
	end)
	return success and canPrompt
end

local canPrompt = canPromptOptIn()
if canPrompt then
	local success, errorMessage = pcall(function()
		ExperienceNotificationService:PromptOptIn()
	end)
end

ExperienceNotificationService.OptInPromptClosed:Once(function()
	script:Destroy()
end)

Also, StarterCharacterScripts and StarterPlayerScripts are only storages.
Every scripts inside these storages are not running, these are only the starter scripts for everyone in the game, and scripts are cloned into the Character (You - Inside workspace) and the Player (You - Inside Players).

So i think that you looked at the wrong place to check if the script got destroyed, you need to check inside the Character or the Player, not inside both storage.

Examples

1 Like

Have you tried testing this in another experience to see if theres something specifically wrong with studio on that place?

I was trying to help fix one of my friends issues and the script didn’t seem to work on the game he was working on but worked just fine in another, with no errors.

Hope you figure it out.