Delete a Local Script

How to delete a local script from a local script?
I tried this:

local player = game.Players.LocalPlayer
player.diedEvent:Destroy()

But then there is an error:


Anyone know how to do this? Thanks!

Try using :Remove or :WaitForChild

1 Like

like this?

player:WaitForChild("diedEvent"):Remove()
1 Like

Is this considered an error?

The stack trace basically traces back what functions called what in the events that lead to the error, it’s useful for debugging to see what function caused the error.

So yes, in a way it’s considered an error.

1 Like

Hmm, but then whats wrong?
I dont know whats wrong!

Try this,

local player = game.Players.LocalPlayer
local event = player:WaitForChild("diedEvent")

event:Destroy()
1 Like

image
line 6 is this

Maybe send us a screenshot of what is in the player while you are testing the game.

1 Like

May I have a screenshot of what this ‘diedEvent’ is?

And also is diedEvent a parent of the player?

1 Like

Sure, this is a work around for an inf live gamepass,
image

This is the diedEvent:

local function teleportToLobby()
	TeleportService:Teleport(8832292226) -- change to lobby ID
end


local function startTimer()
	local timer = 15
	repeat
		timer = timer - 1
		ScreenGui.Died.timer.Text = timer
		wait(1)
	until timer <= 0 or extra_life == true
	if extra_life == true then
		reviveEvent:FireServer()
		ScreenGui.Died.Visible = false
	else
		teleportToLobby()	
	end
end

boughtLifeEvent.OnClientEvent:Connect(function()
	extra_life = true
end)

ScreenGui.Died.continue.MouseButton1Down:connect(function()
	MarketplaceService:PromptProductPurchase(player, 1255419788)-- change to product ID
end)

ScreenGui.Died.btl.MouseButton1Down:connect(function()
	teleportToLobby()
end)

diedEvent.OnClientEvent:Connect(function()
	ScreenGui.Died.Visible = true
	startTimer()
end)

The main thing I want to do is if he have the gamepas, it will cancel the teleporttolobby event, by deleting the script from the other one, the other script (which we have a problem in it):

local Checkifowngamepass = game.ReplicatedStorage.Remotes.CheckIfOwnGamepass
local player = game.Players.LocalPlayer
local ScreenGui = player.PlayerGui.MainGui
local objective = ScreenGui.ObjectiveFrame
local timer = ScreenGui.TimerFrame
local event = player:WaitForChild("diedEvent")


Checkifowngamepass.OnClientEvent:Connect(function()
	if objective.Visible == true then
		objective.Position = UDim2.new(0, 0, 0.5, 0)
		wait(2)
		objective:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0))
		wait(2)
		objective.Visible = false
	end
	if timer.Visible == true then
		timer.Position = UDim2.new(0.5, 0, 0.02, 0)
		wait(2)
		timer:TweenPosition(UDim2.new(0.5, 0, -0.52, 0))
		timer.Visible = false
	end
	event:Destroy()
	repeat wait() until player.PlayerGui.MainGui.Died.Visible == true
	player.PlayerGui.MainGui.Died.Visible = false
	
	
end)

And yes

Oh, I see! Try this…

local Player = game.Players.LocalPlayer
Player.Character:WaitForChild("diedEvent"):Destroy()
1 Like

You Dont Need To Be Sory :wink:

Cuz your script is working! Thank you so much!

1 Like