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
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
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…
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?
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
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 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.
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.