How could I delete a script in the player's character?

Hi!
My script ere should delete a script in the player’s character, but I don’t know how to define the player.
Thanks for any help!

local sound = script.Parent.Parent.ImageLabel.Intro
local btn = script.Parent
local fade = script.Parent.Parent.Parent.fadeLoad
local plr = game.Players.LocalPlayer.Name
btn.MouseButton1Click:Connect(function()
	for i = 1,500 do
		wait (0.01)
		sound.Volume -= 0.01
		fade.BackgroundTransparency -= 0.01
	end
	sound:Pause()
	game.Workspace.HowToIndex.CutsceneScript:Destroy()
	for i = 1, 100 do
		wait (0.01)
		fade.BackgroundTransparency += 0.01
	end
end)


Is this script we see the actual script?

Yes, Unfinished because I ran into this issue.

If you need to delete the script, you can refer to the script the code is running in by doing script.

so like this:

script:Destroy()

I know script:Destroy(), i need to know how to index the LocalPlayer’s character in workspace

(say plr is a variable containing the local player)

do

plr.Character

So game.Workspace.plr.Character.CutsceneScript:Destroy()?

You can just do

plr.Character:WaitForChild("CutsceneScript"):Destroy()

It’ll get the player model automatically.

@goofylamb83 MouseButton1Click has no parameters. You can just define the player with LocalPlayer

do a little bit of this yeah

btn.MouseButton1Click:Connect(function(player)
	local character = player.Character
    character.YourScriptNameHere:Destroy() -- whatever the name of your script is
end)

OR you can do this

wait(0.1)
local player = game.Players.LocalPlayer
local character = player.Character

btn.MouseButton1Click:Connect(function(player)
    character.YourScriptNameHere:Destroy() -- whatever the name of your script is
end)

No. you don’t get the player like that.

When does this code run? Does it run immediately after the game starts?

local sound = script.Parent.Parent.ImageLabel.Intro
local btn = script.Parent
local fade = script.Parent.Parent.Parent.fadeLoad
local plr = game.Players.LocalPlayer.Name
btn.MouseButton1Click:Connect(function()
	for i = 1,500 do
		wait (0.01)
		sound.Volume -= 0.01
		fade.BackgroundTransparency -= 0.01
	end
	sound:Pause()
	plr.Character:WaitForChild("CutsceneScript"):Destroy()
	for i = 1, 100 do
		wait (0.01)
		fade.BackgroundTransparency += 0.01
	end
end)


It runs when you click the button…

btn.MouseButton1Click:Connect(function()

tiny error in your plr variable. this should work

local sound = script.Parent.Parent.ImageLabel.Intro
local btn = script.Parent
local fade = script.Parent.Parent.Parent.fadeLoad
local plr = game.Players.LocalPlayer
btn.MouseButton1Click:Connect(function()
	for i = 1,500 do
		wait (0.01)
		sound.Volume -= 0.01
		fade.BackgroundTransparency -= 0.01
	end
	sound:Pause()
	plr.Character:WaitForChild("CutsceneScript"):Destroy()
	for i = 1, 100 do
		wait (0.01)
		fade.BackgroundTransparency += 0.01
	end
end)

Because you have just done

You don’t need to use Name here.

1 Like

How would I readjust the Camera to Player, since the cutscene is using the camera?
After I stop, it kind of just gets stuck.

Did you mean the camera type? If so, you can just add this into your local script after the last for loop.

for i = 1, 100 do
	wait (0.01)
	fade.BackgroundTransparency += 0.01
end
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
1 Like