Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unable to Destroy()?

I'm trying to figure out what's wrong with my script and why it's not removing the sound script as well as not changing the walkspeed within the Player after they respawn. Any help?

function onPlayerEntered(player)
	repeat wait () until player.Character ~= nil
	Player.Character.Sound:Destroy()
	Player.Character.Humanoid.WalkSpeed = 5
	player.CharacterAdded:connect(function (char)
		Player.Character.Sound:Destroy()
		Player.Character.Humanoid.WalkSpeed = 5		
	end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

4 answers

✓ Accepted answer
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function (char)
        char:WaitForChild("Sound"):Destroy()
	       char:WaitForChild("Humanoid").WalkSpeed = 5 
end)
end)

This should work your script probably broke and ran to early.

Your 6th and 7th line "players" are capitalized, try that?

function onPlayerEntered(player)
    repeat wait () until player.Character ~= nil
    Player.Character.Sound:Destroy()
    Player.Character.Humanoid.WalkSpeed = 5
    Player.CharacterAdded:connect(function (char) -- you had 'player' not 'Player'
        Player.Character.Sound:Destroy()
        Player.Character.Humanoid.WalkSpeed = 5     
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

This should work now.

The first time a player joins, it removes the sound, then after that, it removes it again when the character joins the workspace. you just got to remove lines 3 and 4.

1 comment

0

But when the player respawns the sound comes back again.

This discussion is preserved as it was. New answers, comments, and votes are closed.