Issue with destroying script

Good afternoon!

I was working on a type writer text script and I wanted to delete another script from my game after said line. Here’s the full script:

local textLabel = script.Parent.Main.TextLabel
script.Parent.Enabled = false

wait(10)

script.Parent.Enabled = true

local function typewrite(object, text)
for i = 1, string.len(text) do
	object.Text = string.sub(text,1,i)
	wait(0.05)
end
end

game.Workspace.Talk:Play()
typewrite(textLabel,"You ate a bean burrito and now you're here lol. Run directly at small 
walls to vault over them.")
wait(0.5)
game.Workspace.Talk:Pause()
wait(5)
game.Workspace.Talk:Play()
typewrite(textLabel,"Oh, you can also triple jump in this game, interesting...")
wait(0.5)
game.Workspace.Talk:Pause()
wait(5)
game.Workspace.Talk:Play()
typewrite(textLabel,"Actually, i'm gonna make you pay for that ability, because I have to act 
like an obby dev.")
game.StarterPlayer.StarterCharacterScripts.DoubleJump:Destroy()
wait(0.5)
game.Workspace.Talk:Pause()
wait(5)
game.Workspace.Talk:Play()
typewrite(textLabel,"Walk into the portal to access the obby, and please give me money")
wait(0.5)
game.Workspace.Talk:Stop()
wait(5)
script.Parent.Enabled = false

The thing that’s not working is this part:

game.StarterPlayer.StarterCharacterScripts.DoubleJump:Destroy()

The DoubleJump script goes to the players category when the script boots up. If someone can please help that would be awesome! :smiley: :+1:

(Ps. I’m actually fixing the code to be less messy, it definitely looks bad on my end.)

1 Like

I came by this problem as well while I was working with the starterGUIfolder.
To delete that script, you have to get rid of it inside the player.
When a player respawns, Roblox clones everything inside the StarterCharacterScripts folder to the player, so you need to remove the script from the desired player.

I recommend having the script initially disabled in StarterCharacterScripts and enabling/disabling for each player when needed. That way, if a new player joins and/or the current player dies, the script is not lost.

I hope that helps!

1 Like

Okay, I think I explained it terribly. The script is suppose to start out working, then stop working after the line:

typewrite(textLabel,"Actually, i'm gonna make you pay for that ability, because I have to act 
like an obby dev.")

It is then suppose to make the double jump stop working. The code actually types out the whole line of text before running another line of code.

Is this on a local or server script?

Local. Here’s the hierarchy: diagram

Try this:

local Players = game:GetService("Players")
local player = Players.LocalPlayer

player.CharacterScripts.DoubleJump:Destroy()

Says CharacterScripts is not a valid member of player.

try:

player.PlayerScripts.DoubleJump:Destory()

We are trying to access the script that the player has here

That was what I was trying to do before I made this post.

Players.LocalPlayer.PlayerScripts:FindFirstChild("DoubleJump"):Destroy()

Alright, so it doesn’t get copied over to PlayerScripts. I’m not sure why though. Here’s what the double jump script looks like:

local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local MAX_JUMPS = 3

local TIME_BETWEEN_JUMPS = 0.2
local numJumps = 0
local canJumpAgain = false

local function onStateChanged(oldState, newState)
if Enum.HumanoidStateType.Landed == newState then
numJumps = 0
canJumpAgain = false
elseif Enum.HumanoidStateType.Freefall == newState then
wait(TIME_BETWEEN_JUMPS)
canJumpAgain = true
elseif Enum.HumanoidStateType.Jumping == newState then
canJumpAgain = false
numJumps += 1
end

end

local function onJumpRequest()
if canJumpAgain and numJumps < MAX_JUMPS then

	humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	
end

end

humanoid.StateChanged:Connect(onStateChanged)
UserInputService.JumpRequest:Connect(onJumpRequest)

your code in the first post was accessing starterplayer which is not the current player’s script

Error says the following:

    22:51:40.380  Players.bbgrot.PlayerGui.Scrolling.TypeWriterText:32: attempt to index nil 
    with 'Destroy'  -  Client - TypeWriterText:32

Alright, for some reason, it stays in StarterCharacterScripts. I actually tried to destroy it from StarterCharacterScripts, but it didn’t work.

its entering the character probably, go into:

game.Workspace[player.name]:FindFirstChild("DoubleJump")

I found it in the character. Alright, this is starting to make way more sense.

what? Just replace the method you try to find the script with locating the character

I found it, it went to character instead of player.

I think a script should be added in the same Parent of the undesired script. I recommend using a RemoteEvent or RemoteFunction.

Player is causing errors like this one:

23:06:03.546  Players.bbgrot.PlayerGui.Scrolling.TypeWriterText:27: attempt to index nil with 'name'  -  Client - TypeWriterText:27

Think it’s because the player isn’t being detected when the script is running.